Created
April 26, 2022 14:36
-
-
Save bamoha/fa82686621151e0ac57782171381b441 to your computer and use it in GitHub Desktop.
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
const isAnagram = (s, t) => { | |
if(s.length !== t.length){ | |
return false | |
} | |
let charA = getCharObj(s) | |
let charB = getCharObj(t) | |
for(const keys in charA){ | |
if(charA[keys] !== charB[keys]){ | |
return false; | |
} | |
} | |
return true; | |
}; | |
const getCharObj = (string) =>{ | |
let charCount = {} | |
for(const aVals of string){ | |
charCount[aVals] = charCount[aVals] ? charCount[aVals] + 1 : 1 | |
} | |
return charCount; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment