Find position of given term in a series formed with only digits 4 and 7 allowed | Function to find the position of the number N ; To store the position of N ; Iterate through all digit of N ; If current digit is 7 ; If current digit is 4 ; Prvar the final position ; Given number of the series ; Function Call
function findPosition ( n ) { var i = 0 ; var pos = 0 ; while ( n > 0 ) { if ( n % 10 == 7 ) { pos = pos + parseInt ( Math . pow ( 2 , i + 1 ) ) ; } else { pos = pos + parseInt ( Math . pow ( 2 , i ) ) ; } i ++ ; n = parseInt ( n / 10 ) ; } document . write ( pos ) ; } var N = 777 ; findPosition ( N ) ;