mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
936 B
32 lines
936 B
var baseFlatten = require('../internal/baseFlatten'),
|
|
isIterateeCall = require('../internal/isIterateeCall');
|
|
|
|
/**
|
|
* Flattens a nested array. If `isDeep` is `true` the array is recursively
|
|
* flattened, otherwise it's only flattened a single level.
|
|
*
|
|
* @static
|
|
* @memberOf _
|
|
* @category Array
|
|
* @param {Array} array The array to flatten.
|
|
* @param {boolean} [isDeep] Specify a deep flatten.
|
|
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
|
|
* @returns {Array} Returns the new flattened array.
|
|
* @example
|
|
*
|
|
* _.flatten([1, [2, 3, [4]]]);
|
|
* // => [1, 2, 3, [4]]
|
|
*
|
|
* // using `isDeep`
|
|
* _.flatten([1, [2, 3, [4]]], true);
|
|
* // => [1, 2, 3, 4]
|
|
*/
|
|
function flatten(array, isDeep, guard) {
|
|
var length = array ? array.length : 0;
|
|
if (guard && isIterateeCall(array, isDeep, guard)) {
|
|
isDeep = false;
|
|
}
|
|
return length ? baseFlatten(array, isDeep) : [];
|
|
}
|
|
|
|
module.exports = flatten;
|
|
|