All the characters are checked whether it 's either not replaced or replaced  by a similar character using a map.
var mp = { } ; for ( var i = 0 ; i < s1 . length ; i ++ ) { if ( ! mp . hasOwnProperty ( s1 [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ) ) { mp [ s1 [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] = s2 [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ; } else { if ( mp [ s1 [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ] !== s2 [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ) return false ; } }