const map = new Map();
const [key, value] = Array.from(map)
map.values();
map.keys()
The
Array.from
method converts the iterable into an array and returns the new array instance.
const [key, value] = Object.entries(map);
const isAnagram = function (s, t) {
if (s.length !== t.length) {
return false;
}
const sObj = {};
const tObj = {};
for (let i = 0; i < s.length; i++) {
if (!sObj[s[i]]) {
sObj[s[i]] = 1;
} else {
sObj[s[i]]++;
}
}
for (let i = 0; i < t.length; i++) {
if (!tObj[t[i]]) {
tObj[t[i]] = 1;
} else {
tObj[t[i]]++;
}
}
// compare
for (const [key, value] of Object.entries(sObj)) {
if (value !== tObj[key]) {
return false;
}
}
return true;
};