Set found variable to false whenever we find whitespace , meaning that encoded character for new word is not found
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 ( ) ; }