1const areAnagram = (str1, str2) => str1.toLowerCase().split('').sort().join('') === str2.toLowerCase().split('').sort().join('');
2
3// Examples
4areAnagram('listen', 'silent'); // true
5areAnagram('they see', 'the eyes'); // true
6areAnagram('node', 'deno'); // true
1function isAnagram(stringA, stringB) {
2 // Sanitizing
3 stringA = stringA.toLowerCase().replace(/[\W_]+/g, "");
4 stringB = stringB.toLowerCase().replace(/[\W_]+/g, "");
5
6 // sorting
7 const stringASorted = stringA.split("").sort().join("");
8 const stringBSorted = stringB.split("").sort().join("");
9
10 return stringASorted === stringBSorted;
11}
1function anagram(name, words) {
2 name = name.toLowerCase().split('').sort().join('').trim();
3 words = words.join('').toLowerCase().split('').sort().join('');
4 return name === words;
5}