Arrays & Iterables

Count Array Items by Iteratee

easyJS SpecificJS / TS3 tests

Problem Statement

Implement `countBy(array, iteratee)` that groups array elements according to the result of `iteratee` and returns an object with the count of items in each group.

Examples

Example 1:
countBy([6.1, 4.2, 6.3], Math.floor); // { '4': 1, '6': 2 }

Example 2:
countBy(['one', 'two', 'three'], 'length'); // { '3': 2, '5': 1 }
JavaScript & TypeScript starter code included
Run this as a live interview

Practice solo

3 test cases. No second person needed.

Get new interview exercises

Practice problems and review drills, sent when we publish new ones. No spam.

Unsubscribe anytime. We never share your address.