n | javascript code to find nth number with digits 0 , 1 , 2 , 3 , 4 , 5 ; function to convert num to base 6 ; initialize an array to 0 ; function calling to convert number n to base 6 ; if size is zero then return zero
var max = 100000 ; function baseconversion ( arr , num , base ) { var i = 0 , rem , j ; if ( num == 0 ) { return 0 ; } while ( num > 0 ) { rem = num % base ; arr [ i ++ ] = rem ; num = parseInt ( num / base ) ; } return i ; } var arr = Array ( max ) . fill ( 0 ) ; var n = 10 ; var size = baseconversion ( arr , n - 1 , 6 ) ; if ( size == 0 ) document . write ( size ) ; for ( i = size - 1 ; i >= 0 ; i -- ) { document . write ( arr [ i ] ) ; }