This question already has an answer here:
- Partitioning in JavaScript [duplicate] 7 answers
Let's say I have an array = [0,1,2,3,4,5,6] and I want to "partition" it into 3 arrays, based on reminder after division by 3.
so basically I'd want something like:
_.my_partition([0,1,2,3,4,5,6], function(item) {return item % 3;})
// [[0,3,6], [1,4],[2,5]]
(I can use lodash, underscore, if ti helps...)
There are multiple to do this:
I. Normal function
II. Adding a prototype method
Create an _.partitionToGroups method