easy+150 XPPractice
Count how often each value appears
Filter sidebars show a count next to every option, dashboards show how many events of each type arrived, and a tag cloud sizes each tag by its tally. All of it is the same one-pass count.
Implement countFrequencies(items). items is an array of primitive values (strings, numbers or booleans). Return a plain object whose keys are the string form of each distinct value and whose values are how many times that value appeared. An empty array returns an empty object. Do not modify the input array.
What it has to do
- Return a plain object mapping the string form of each value to its count.
- Return an empty object for an empty array.
- Count numbers and booleans as well as strings.
- Do not mutate the input array.
Your workspace
Try it yourself· Edit the code, then press Run
Loading playground...
Ready to check it?
5 tests run against your code, right here in your browser. Sign in to claim the XP when you pass.
AI Crack & Solution Assist
Stuck? Get instant AI hints or break down the optimal solution.
Stuck? The javascript course covers everything this challenge needs.