Print N | function to generate n digit numbers ; if number generated ; Append 1 at the current number and reduce the remaining places by one ; If more ones than zeros , append 0 to the current number and reduce the remaining places by one ; driver function ; Function call
function printRec ( number , extraOnes , remainingPlaces ) { if ( 0 == remainingPlaces ) { document . write ( number + " " ) ; return ; } printRec ( number + " " , extraOnes + 1 , remainingPlaces - 1 ) ; if ( 0 < extraOnes ) printRec ( number + " " , extraOnes - 1 , remainingPlaces - 1 ) ; } function printNums ( n ) { let str = " " ; printRec ( str , 0 , n ) ; } let n = 4 ; printNums ( n ) ;