My first solution (ES2019) looks like this:
const isAnagram = (word1, word2) => { const charsInWord = {}; const maxLength = Math.max(word1.length, word2.length); for (let index = 0; index < maxLength; index++) { const char1 = word1.charCodeAt(index); const char2 = word2.charCodeAt(index); if (char1 >= 97 && char1 <= 122) { charsInWord[char1] = (charsInWord[char1] || 0) + 1; } if (char2 >= 97 && char2 <= 122) { charsInWord[char2] = (charsInWord[char2] || 0) - 1; } } return (Object.values(charsInWord) || { a: 0 }).every((charCount) => charCount === 0); }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
My first solution (ES2019) looks like this: