Check for a subsequence of size 1
for ( let j = 0 ; j < S . length ; j ++ ) { if ( S [ j ] != ' ' && S [ j ] != ' ' && S [ j ] != ' ' && S [ j ] != ' ' ) { document . write ( 1 ) ; flag = true ; break ; } }