Home
← All questions

Implement _.groupBy (Lodash) in JavaScript

MediumPremiumJavaScript

Asked at Meesho

JavaScript interview practice: Group collection items by a function or a property path, supporting deep paths like 'a.b.c'.

Problem

Implement groupBy(collection, iteratee). The iteratee can be a function, or a string property path (including deep paths such as "address.city"). Return an object mapping each computed key to the array of items that produced it.

function groupBy(collection, iteratee) {
  // your code
}
Premium question

Unlock the in-browser editor, test cases, and model solution with Mentoxis Premium.

Unlock with Premium