challenge-algorithms-v2.0-m.../08-isAnagram/index.js

11 lines
232 B
JavaScript
Raw Normal View History

export function isAnagram(word1, word2) {
2022-11-02 22:34:23 +00:00
const normalize = (str) =>
str
.toLowerCase()
.replace(/[^a-z0-9]/gi, "")
.split("")
.sort()
.join("");
return normalize(word1) === normalize(word2);
}