Created
March 28, 2019 00:00
-
-
Save mcabreradev/ca692f0907438727f0449d9ba7ff52f7 to your computer and use it in GitHub Desktop.
common functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
isAnagram | |
Checks if a string is an anagram of another string (case-insensitive, ignores spaces, punctuation and special characters). | |
*/ | |
const isAnagram = (str1, str2) => { | |
const normalize = str => | |
str | |
.toLowerCase() | |
.replace(/[^a-z0-9]/gi, '') | |
.split('') | |
.sort() | |
.join(''); | |
return normalize(str1) === normalize(str2); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment