Check Whether Two Strings are Almost Equivalent LeetCode solution in JavaScript

1
var checkAlmostEquivalent = function (word1, word2) {
2
const hm = new Map();
3
const addToHm = (ch, add) => {
4
if (hm.has(ch)) hm.set(ch, hm.get(ch) + (add ? +1 : -1));
5
else hm.set(ch, add ? +1 : -1);
6
};
7

8
for (let i = 0; i < word1.length; i++) {
9
addToHm(word1[i], true);
10
addToHm(word2[i], false);
11
}
12

13
for (const val of hm.values()) if (Math.abs(val) > 3) return false;
14

15
return true;
16
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0