JavaScript算法试题系列-04 发表于 2017-06-15 | 更新于 2017-06-15 | 分类于 学习笔记 , JavaScript | | 共 108 字 | 阅读 次 题目要求: 1234// 乱序同字母字符串给定两个字符串,判断是否颠倒字母而成的字符串,譬如Mary与Army就是同字母而顺序颠倒:var firstWord = "Mary";var secondWord = "Army";isAnagram(firstWord, secondWord); // true 解答: 1234567891011function isAnagram(first, second) { // For case insensitivity, change both words to lowercase. var a = first.toLowerCase(); var b = second.toLowerCase(); // Sort the strings, and join the resulting array to a string. Compare the results a = a.split("").sort().join(""); b = b.split("").sort().join(""); return a === b;} ------ 本文结束 ------ 版权声明 加州提子面包 by MiG is licensed under a Creative Commons BY-NC-SA 4.0 International License. 由MiG创作并维护的加州提子面包博客采用「创作共用保留署名-非商业性使用-相同方式共享」4.0国际许可证. 本文首发于加州提子面包 博客( https://gihcctpd.github.io ),版权所有,侵权必究.