Modify characters of a string by adding integer values of same | Function to modify a given string by adding ASCII value of characters from a string S to integer values of same indexed characters in string N ; Traverse the string ; Stores integer value of character in string N ; Stores ASCII value of character in string S ; If b exceeds 122 ; Replace the character ; Print resultant string ; Given strings ; Function call to modify string S by given operations
function addASCII ( S , N ) { var newStr = new Array ( S . length ) ; for ( var i = 0 ; i < S . length ; i ++ ) { var a = N [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ; var b = S [ i ] . charCodeAt ( 0 ) + a ; if ( b > 122 ) b -= 26 ; newStr [ i ] = String . fromCharCode ( b ) ; } document . write ( newStr . join ( " " ) ) ; } var S = " " , N = " " ; addASCII ( S , N ) ;