Find n | javascript program to find n - th number containing only 4 and 7. ; If n is odd , append 4 and move to parent ; If n is even , append 7 and move to parent ; Reverse res and return . ; Driver code
function findNthNo ( n ) { res = " " ; while ( n >= 1 ) { if ( ( n & 1 ) == 1 ) { res = res + " " ; n = ( n - 1 ) / 2 ; } else { res = res + " " ; n = parseInt ( ( n - 2 ) / 2 ) ; } } return res . split ( " " ) . reverse ( ) . join ( " " ) ; } var n = 13 ; document . write ( findNthNo ( n ) ) ;