Frequency Counter

Hash Maps · easy

Implement `frequency(arr)` that returns an object mapping each unique element of `arr` to the number of times it appears. Example: `frequency(['a','b','a','c','b','a'])` → `{ a: 3, b: 2, c: 1 }`.

Hints
  • Use a plain object as a counter.
  • For each element, increment its count in the map (defaulting to 0 if missing).

Learning resources

Loading...

Run your code to see results.