123456789101112 |
- export const group_by = (array, key) => {
- return array.reduce((result, currentValue) => {
- (result[currentValue[key]] = result[currentValue[key]] || []).push(
- currentValue
- );
- return result;
- }, {});
- };
- export const chunk = (arr, size) => arr.reduce((chunks, el, i) => (i % size
- ? chunks[chunks.length - 1].push(el)
- : chunks.push([el])) && chunks, []
- )
|