Null Cipher | Function to decode the message . ; Store the decoded string ; found variable is used to tell that the encoded encoded character is found in that particular word . ; Set found variable to false whenever we find whitespace , meaning that encoded character for new word is not found ; Driver Code
function decode ( str ) { let res = " " ; let found = false ; for ( let i = 0 ; i < str . length ; i ++ ) { if ( str [ i ] == ' ' ) { found = false ; continue ; } if ( ! found ) { if ( ( str [ i ] >= ' ' && str [ i ] <= ' ' ) || ( str [ i ] >= ' ' && str [ i ] <= ' ' ) ) { res += ( str [ i ] ) ; found = true ; } } } return res . toLowerCase ( ) ; } let In = " " ; document . write ( " " + decode ( In ) ) ;