Question with below code.
If I’m decreasing the object value and when it comes to zero how it is satisfying this condition if(!obj1[letter]) because letter still exist in obj, its value is just going down.
function validAnagram(a, b){
if(a.length !== b.length){
return false;
}
if(a.length === 0 && b.length === 0 ){
return true;
}
let obj1 = {};
// add whatever parameters you deem necessary - good luck!
for(let i= 0; i<a.length; i++){
if(obj1[a[i]]>0){
obj1[a[i]]++
}else{
obj1[a[i]] = 1;
}
}
for(let i =0; i<b.length; i++){
let letter = b[i];
if(!obj1[letter]){
return false
} else {
obj1[letter]--
}
}
return true;
}
validAnagram('aza', 'zaz')