JSFiddle - React, Tailwind, and code Playground
JavaScript
//console.log(isIsomorphic("egg", 'add')); // true
//console.log(isIsomorphic("egg", 'sad')); // false
//console.log(isIsomorphic("dgg", 'add')); // true
//console.log(isIsomorphic("paper", 'title'))
//console.log(isIsomorphic("kick", 'side'))
console.log(isIsomorphic('sbc', 'abb'))
function isIsomorphic(firstString, secondString) {
if (firstString.length !== secondString.length) return false;
let hash = {};
for (var i = 0; i < firstString.length; i++) {
let l_a = firstString[i];
let l_b = secondString[i];
if (!hash[l_a]) {
if (secondString.indexOf(l_b) < i) {
return false
} else {
hash[l_a] = l_b;
}
} else if (hash[l_a] !== l_b) {
return false;
}
}
return true;
}