1function anagram(name, words) {
2 var a = name.replace(/\s/g,'').toLowerCase().split('').sort().join('');
3 var b = words.join('').split('').sort().join('');
4 return a == b;
5}
1 function group_anagrams(arr) {
2 let sortedArr = arr.map(item => item.split('').sort().join(''));
3 let setArr = new Set(sortedArr);
4 let reducedObj = {};
5 for (let setItem of setArr) {
6 let indexArr = sortedArr.reduce((acc, cur, index) => {
7 if (setItem === cur) {
8 acc.push(index);
9 }
10 return acc;
11 }, []);
12 reducedObj[setItem] = indexArr;
13 }
14 let finalArr = [];
15 for (let reduceItem in reducedObj) {
16 finalArr.push(reducedObj[reduceItem].map(item => arr[item]));
17 }
18 return finalArr;
19 }
20 group_anagrams(['car','cra','rca', 'cheese','ab','ba']);
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}