mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-02 08:07:50 +00:00
Bump to v4.0.0.
This commit is contained in:
30
flatMap.js
Normal file
30
flatMap.js
Normal file
@@ -0,0 +1,30 @@
|
||||
import arrayMap from './internal/arrayMap';
|
||||
import baseFlatten from './internal/baseFlatten';
|
||||
import baseIteratee from './internal/baseIteratee';
|
||||
|
||||
/**
|
||||
* Creates an array of flattened values by running each element in `array`
|
||||
* through `iteratee` and concating its result to the other mapped values.
|
||||
* The iteratee is invoked with three arguments: (value, index|key, array).
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Array
|
||||
* @param {Array} array The array to iterate over.
|
||||
* @param {Function|Object|string} [iteratee=_.identity] The function invoked per iteration.
|
||||
* @returns {Array} Returns the new array.
|
||||
* @example
|
||||
*
|
||||
* function duplicate(n) {
|
||||
* return [n, n];
|
||||
* }
|
||||
*
|
||||
* _.flatMap([1, 2], duplicate);
|
||||
* // => [1, 1, 2, 2]
|
||||
*/
|
||||
function flatMap(array, iteratee) {
|
||||
var length = array ? array.length : 0;
|
||||
return length ? baseFlatten(arrayMap(array, baseIteratee(iteratee, 3))) : [];
|
||||
}
|
||||
|
||||
export default flatMap;
|
||||
Reference in New Issue
Block a user