SIGN IN SIGN UP

A modern JavaScript utility library delivering modularity, performance, & extras.

0 0 9 JavaScript
2016-02-01 23:13:04 -08:00
define(['./_baseFlatten', './map'], function(baseFlatten, map) {
2015-12-16 17:53:20 -08:00
/**
2016-03-26 00:00:01 -07:00
* Creates a flattened array of values by running each element in `collection`
2016-04-01 23:28:48 -07:00
* thru `iteratee` and flattening the mapped results. The iteratee is invoked
* with three arguments: (value, index|key, collection).
2015-12-16 17:53:20 -08:00
*
* @static
* @memberOf _
2016-03-26 00:00:01 -07:00
* @since 4.0.0
2016-02-01 23:13:04 -08:00
* @category Collection
* @param {Array|Object} collection The collection to iterate over.
2016-10-30 20:06:57 -07:00
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
2016-02-01 23:13:04 -08:00
* @returns {Array} Returns the new flattened array.
2015-12-16 17:53:20 -08:00
* @example
*
* function duplicate(n) {
* return [n, n];
* }
*
* _.flatMap([1, 2], duplicate);
* // => [1, 1, 2, 2]
*/
2016-02-01 23:13:04 -08:00
function flatMap(collection, iteratee) {
2016-02-15 20:20:54 -08:00
return baseFlatten(map(collection, iteratee), 1);
2015-12-16 17:53:20 -08:00
}
return flatMap;
});