Print all numbers less than N with at | Javascript program to print all the numbers less than N which have at most 2 unique digits ; Function to generate all possible numbers ; If the number is less than n ; If the number exceeds ; Check if it is not the same number ; Function to print all numbers ; All combination of digits ; Print all numbers ; Driver code
let st = new Set ( ) ; function generateNumbers ( n , num , a , b ) { if ( num > 0 && num < n ) st . add ( num ) ; if ( num >= n ) return ; if ( num * 10 + a > num ) generateNumbers ( n , num * 10 + a , a , b ) ; generateNumbers ( n , num * 10 + b , a , b ) ; } function printNumbers ( n ) { for ( let i = 0 ; i <= 9 ; i ++ ) for ( let j = i + 1 ; j <= 9 ; j ++ ) generateNumbers ( n , 0 , i , j ) ; document . write ( " " ) ; document . write ( Array . from ( st ) . sort ( function ( a , b ) { return a - b ; } ) . join ( " " ) ) ; st . clear ( ) ; } let n = 12 ; printNumbers ( n ) ;