OneCompiler

Anagram or not

138

// Anagram or not .....
function isAnagram(str1,str2){
if(str1.length!=str2.length){
return false
}
let counter={}
for(let item of str1)
counter[item]=(counter[item]||0)+1

for(let item of str2)
if(!counter[item])
return false
else
counter[item]--

return true

}

console.log(isAnagram('hello','lhoel'))