0
Hours
0
Minutes
0
Seconds
You need Login/Signup to run/submit the code.

How to implement lodash groupBy functionality from scratch? | JavaScript Interview Question | Frontend Problem Solving

@Yomesh Gupta
594

You have to write your own implementation of _.groupBy.

// _.groupBy(collection, [iteratee=_.identity])
_.groupBy([6.1, 4.2, 6.3], Math.floor);
// => { '4': [4.2], '6': [6.1, 6.3] }
 
// The `_.property` iteratee shorthand.
_.groupBy(['one', 'two', 'three'], 'length');
// => { '3': ['one', 'two'], '5': ['three'] }

Demo:

For more -- https://lodash.com/docs/4.17.15#groupBy

Loading IDE...