Boolean array to mark presence of characters
var mark = Array ( 26 ) . fill ( false ) ; var n = str1 . length , m = str2 . length ; for ( var i = 0 ; i < n ; i ++ ) { mark [ str1 [ i ] - ' ' ] = true ; }