helpers.js 399 B

123456789101112
  1. export const group_by = (array, key) => {
  2. return array.reduce((result, currentValue) => {
  3. (result[currentValue[key]] = result[currentValue[key]] || []).push(
  4. currentValue
  5. );
  6. return result;
  7. }, {});
  8. };
  9. export const chunk = (arr, size) => arr.reduce((chunks, el, i) => (i % size
  10. ? chunks[chunks.length - 1].push(el)
  11. : chunks.push([el])) && chunks, []
  12. )