Minimize sum of given array by removing all occurrences of a single digit | Function to remove each digit from the given integer ; Convert into string ; Stores final string ; Traverse the string ; Append it to the final string ; Return integer value ; Function to find the minimum sum by removing occurences of each digit ; Iterate in range [ 0 , 9 ] ; Traverse the array ; Update the minimum sum ; Print the minimized sum ; Driver program to test above functions
function remove ( N , digit ) { var strN = N . toString ( ) ; var ans = " " ; var i ; for ( i = 0 ; i < strN . length ; i ++ ) { if ( ( strN . charCodeAt ( i ) - 48 ) == digit ) { continue ; } ans += strN [ i ] ; } return parseInt ( ans ) ; } function getMin ( arr ) { var minSum = 1000000000 ; var i , j ; for ( i = 0 ; i < 10 ; i ++ ) { var curSum = 0 ; for ( j = 0 ; j < arr . length ; j ++ ) { curSum += remove ( arr [ j ] , i ) ; } minSum = Math . min ( minSum , curSum ) ; } document . write ( minSum ) ; } var arr = [ 34 , 23 , 85 , 93 ] ; getMin ( arr ) ;