helpers.js 727 B

123456789101112131415161718192021222324252627
  1. export const focus = node => node.focus();
  2. export const group_by = (array, key) => {
  3. return array.reduce((result, currentValue) => {
  4. (result[currentValue[key]] = result[currentValue[key]] || []).push(
  5. currentValue
  6. );
  7. return result;
  8. }, {});
  9. };
  10. export const chunk = (arr, size) =>
  11. arr.reduce(
  12. (chunks, el, i) =>
  13. (i % size ? chunks[chunks.length - 1].push(el) : chunks.push([el])) &&
  14. chunks,
  15. []
  16. );
  17. export const sort_by_name = (a, b) => {
  18. var nameA = a.name.toUpperCase(); // ignore upper and lowercase
  19. var nameB = b.name.toUpperCase(); // ignore upper and lowercase
  20. if (nameA < nameB) {
  21. return -1;
  22. }
  23. if (nameA > nameB) {
  24. return 1;
  25. }
  26. return 0;
  27. }