0e05fd884057dfb1d0c034c2418396b7899c3ad18645413e6c845e3532a6553f2ff97b2fac9d2e53cc409c7a673dfc0ad319b01cb02fbbbc55e37f2be9bd94 730 B

12345678910111213141516171819202122232425262728293031
  1. 'use strict';
  2. /**
  3. * Concat and flattens non-null values.
  4. * Ex: concat(1, undefined, 2, [3, 4]) = [1, 2, 3, 4]
  5. */
  6. function concat() {
  7. const args = Array.from(arguments).filter(e => e != null);
  8. const baseArray = Array.isArray(args[0]) ? args[0] : [args[0]];
  9. return Array.prototype.concat.apply(baseArray, args.slice(1));
  10. }
  11. /**
  12. * Dedupes array based on criterion returned from iteratee function.
  13. * Ex: uniqueBy(
  14. * [{ id: 1 }, { id: 1 }, { id: 2 }],
  15. * val => val.id
  16. * ) = [{ id: 1 }, { id: 2 }]
  17. */
  18. function uniqueBy(arr, fun) {
  19. const seen = {};
  20. return arr.filter(el => {
  21. const e = fun(el);
  22. return !(e in seen) && (seen[e] = 1);
  23. })
  24. }
  25. module.exports = {
  26. concat: concat,
  27. uniqueBy: uniqueBy
  28. };