Created
January 10, 2019 13:29
-
-
Save imsarvesh/fcc6ca420161a3f6e5f9839f4995afc2 to your computer and use it in GitHub Desktop.
This file contains 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
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