Generate all possible strings such that char at index i is either str1 [ i ] or str2 [ i ] | Recursive function to generate the required strings ; If length of the current string is equal to the length of the given strings then the current string is part of the result ; Choosing the current character from the string a ; Choosing the current character from the string b ; Driver code ; Third argument is an empty string that we will be appended in the recursion calls Fourth arguments is the length of the resultant string so far
function generateStr ( a , b , s , count , len ) { if ( count == len ) { document . write ( s + " " ) ; return ; } generateStr ( a . substring ( 1 ) , b . substring ( 1 ) , s + a [ 0 ] , count + 1 , len ) ; generateStr ( a . substring ( 1 ) , b . substring ( 1 ) , s + b [ 0 ] , count + 1 , len ) ; } var a = " " , b = " " ; var n = a . length ; generateStr ( a , b , " " , 0 , n ) ;