Isomorphic Strings using JavaScript Map
by landro
Below is a logic puzzle called Isomorphic Strings I have no idea where this came from, but have run into it a couple times playing with leetcode or other frontend learning resources. What got me excited was the opportunity to use JavaScript's Map() feature to hold the Key-Value pairs in the comparison. I feel that it makes the isomorphic string matching implementation much more readable & maintainable.
The Isomorphic Strings Problem
Two strings string1
and string2
are called isomorphic if there is a one to one mapping possible for every character of string1
to every character of string2
. And all occurrences of every character in string1
map to same character in string2
See the Pen Isomorphic Strings with Map() by jlandro (@adhocracy) on CodePen.