1. //检查给定的字符串是否是同构的
    2. //为了使两个字符串同构,字符串a中出现的所有字符都可以用另一个字符替换
    3. //获取字符串b,必须保留字符的顺序。的任何一个字符都必须有一对一的映射
    4. //字符串A到字符串B的每个字符
    5. // paper and title is isomorphic.
    6. // egg and sad is not isomorphic.
    7. // dgg and add is isomorphic.
    8. //解题要点:同构代表两个字符串中每个位置上字符在自身第一次出现的索引相同
    9. function isIsomorphic(firstStr, secondStr) {
    10. if (!firstStr || !secondStr) return false;
    11. const s = firstStr.split('').map(str => firstStr.indexOf(str));
    12. const t = secondStr.split('').map(str => secondStr.indexOf(str));
    13. return s.join('') === t.join('');
    14. }
    15. console.log(isIsomorphic('paper', 'title'));
    16. console.log(isIsomorphic('egg', 'sad'));
    17. console.log(isIsomorphic('dgg', 'add'));