employer cover photo
employer logo

SendGrid Interview Question

Taking an array of strings, return an array with the first instance of any string whose anagram is later in the array (preserving order, removing the later anagram instances and any strings without anagrams)

Interview Answer

Anonymous

Oct 7, 2019

let result = []; const AnagramFinder = () => { s.forEach((word, index) => { let sorted = word .split("") .sort() .join(""); if (!result.includes(sorted)) { result.push(sorted); } }); return result; };