UI for Zipcoin Blue

flatMapDeep.js 796B

1234567891011121314151617181920212223242526272829303132
  1. var baseFlatten = require('./_baseFlatten'),
  2. map = require('./map');
  3. /** Used as references for various `Number` constants. */
  4. var INFINITY = 1 / 0;
  5. /**
  6. * This method is like `_.flatMap` except that it recursively flattens the
  7. * mapped results.
  8. *
  9. * @static
  10. * @memberOf _
  11. * @since 4.7.0
  12. * @category Collection
  13. * @param {Array|Object} collection The collection to iterate over.
  14. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  15. * @returns {Array} Returns the new flattened array.
  16. * @example
  17. *
  18. * function duplicate(n) {
  19. * return [[[n, n]]];
  20. * }
  21. *
  22. * _.flatMapDeep([1, 2], duplicate);
  23. * // => [1, 1, 2, 2]
  24. */
  25. function flatMapDeep(collection, iteratee) {
  26. return baseFlatten(map(collection, iteratee), INFINITY);
  27. }
  28. module.exports = flatMapDeep;