Skip to content

Instantly share code, notes, and snippets.

@bamoha
Created April 26, 2022 14:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bamoha/fa82686621151e0ac57782171381b441 to your computer and use it in GitHub Desktop.
Save bamoha/fa82686621151e0ac57782171381b441 to your computer and use it in GitHub Desktop.
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