function checkPermutation(string1, string2) {
const charCount1 = getCountMap(string1);
const charCount2 = getCountMap(string2);
return charCountsMatch(charCount1, charCount2);
}
function getCountMap(string) {
return string.split('').reduce((map, char) => {
(map[char] && map[char]++) || (map[char] = 1);
return map;
}, {});
}
function charCountsMatch(map1, map2) {
if (Object.keys(map1).length !== Object.keys(map2).length) return false;
for (const key in map1) {
if (map1[key] !== map2[key]) return false;
}
return true;
}
function checkPermutationBitwise(string1, string2) {
let signature1, signature2 = 0;
string1.split('').forEach((char) => {
signature1 ^= char.charCodeAt(0);
});
string2.split('').forEach((char) => {
signature2 ^= char.charCodeAt(0);
});
return signature1 === signature2;
}