Print all the permutation of length L using the elements of an array | Iterative | Convert the number to Lth base and print the sequence ; Sequence is of length L ; Print the ith element of sequence ; Print all the permuataions ; There can be ( len ) ^ l permutations ; Convert i to len th base ; Driver code ; function call
function convert_To_Len_th_base ( n , arr , len , L ) { for ( i = 0 ; i < L ; i ++ ) { document . write ( parseInt ( arr [ n % len ] ) ) ; n = parseInt ( n / len ) ; } document . write ( " " ) ; } function print ( arr , len , L ) { for ( var i = 0 ; i < parseInt ( Math . pow ( len , L ) ) ; i ++ ) { convert_To_Len_th_base ( i , arr , len , L ) ; } } var arr = [ 1 , 2 , 3 ] ; var len = arr . length ; var L = 2 ; print ( arr , len , L ) ;