Find smallest possible Number from a given large Number with same count of digits | Function for finding the smallest possible number after swapping the digits any number of times ; Variable to store the final answer ; Array to store the count of occurrence of each digit ; Loop to calculate the number of occurrences of every digit ; Loop to get smallest number ; Returning the answer ; Driver code
function smallestPoss ( s , n ) { var ans = " " ; var arr = Array ( 10 ) . fill ( 0 ) ; for ( var i = 0 ; i < n ; i ++ ) { arr [ s [ i ] . charCodeAt ( 0 ) - 48 ] ++ ; } for ( var i = 0 ; i < 10 ; i ++ ) { for ( var j = 0 ; j < arr [ i ] ; j ++ ) ans = ans + i . toString ( ) ; } return ans ; } var N = 15 ; var K = " " ; document . write ( smallestPoss ( K , N ) ) ;