Back to Problem Library
Arrays & Objects

Group By Polyfill

easyJS / TS

Problem Statement

Write a method or function `groupBy(array, fn)` that splits an array into an object grouped by the key returned from `fn(item)`.

Examples

Example:
groupBy([6.1, 4.2, 6.3], Math.floor) -> { '4': [4.2], '6': [6.1, 6.3] }
Includes TypeScript & JavaScript starter code
Start Interview with this Problem