https://leetcode.com/problems/valid-anagram/
Solution 1
/**
* @param {string} s
* @param {string} t
* @return {boolean}
*/
var isAnagram = function (s, t) {
if (s.length !== t.length) {
return false;
}
const hashMapS = {};
const hashMapT = {};
for (let i = 0; i < s.length; i++) {
if (hashMapS[s[i]]) {
hashMapS[s[i]] += 1;
} else {
hashMapS[s[i]] = 1;
}
if (hashMapT[t[i]]) {
hashMapT[t[i]] += 1;
} else {
hashMapT[t[i]] = 1;
}
}
const compareST = Object.entries(hashMapS).map(([key, value]) => {
console.log(value, hashMapT[key]);
console.log(value === hashMapT[key]);
if (value === hashMapT[key]) {
return true;
}
return false;
});
return compareST.every((b) => b);
};