Recursive program to insert a star between pair of identical characters | Recursive Javascript program to insert * between two consecutive same characters . ; Function to insert * at desired position ; Append current character ; If we reached last character ; If next character is same , append ' * ' ; Driver code
let output = " " ; function pairStar ( input , i ) { output = output + input [ i ] ; if ( i == input . length - 1 ) return ; if ( input [ i ] == input [ i + 1 ] ) output = output + ' ' ; pairStar ( input , i + 1 ) ; } let input = " " ; pairStar ( input , 0 ) ; document . write ( output ) ;