Skip to content

Instantly share code, notes, and snippets.

@imsarvesh
Created January 10, 2019 13:29
Show Gist options
  • Save imsarvesh/fcc6ca420161a3f6e5f9839f4995afc2 to your computer and use it in GitHub Desktop.
Save imsarvesh/fcc6ca420161a3f6e5f9839f4995afc2 to your computer and use it in GitHub Desktop.
var isAnagrams = (str1,str2) => {
var charCount = new Map();
for(var c of str1.split('')){
charCount.set(c, (charCount.get(c) || 0) + 1);
}
for(var c of str2.split('')){
if(!charCount.has(c)) return false;
charCount.set(c, charCount.get(c) - 1);
}
return Array.from(charCount.values()).every(val => val === 0)
}
var str1 = 'heart1';
var str2 = 'earth';
isAnagrams(str1, str2); //true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment