Count occurrences of each word in "to be or not to be".
Ready — edit the code above and click Run.
const s = "to be or not to be";
const freq = {};
for (const w of s.split(" ")) freq[w] = (freq[w] || 0) + 1;
console.log(freq);
Try solving on your own first, then reveal the official answer.
Object as hash map—same idea as MongoDB $group or SQL GROUP BY.