Generate all possible strings formed by replacing letters with given respective symbols | Function to generate all possible string by replacing the characters with mapped symbols ; Base Case ; Function call with the P - th character not replaced ; Replace the P - th character ; Function call with the P - th character replaced ; Driver Code ; Function Call
function generateLetters ( S , P , M ) { if ( P == S . length ) { document . write ( S + " " ) ; return ; } generateLetters ( S , P + 1 , M ) ; S = S . replace ( S . charAt ( P ) , M . get ( S [ P ] ) ) generateLetters ( S , P + 1 , M ) ; return ; } let S = " " ; let M = new Map ( ) ; M . set ( ' ' , ' ' ) ; M . set ( ' ' , ' ' ) ; M . set ( ' ' , ' ' ) ; M . set ( ' ' , ' ' ) ; M . set ( ' ' , ' ' ) ; M . set ( ' ' , ' ' ) ; M . set ( ' ' , ' ' ) ; generateLetters ( S , 0 , M ) ;