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.
19 lines
369 B
19 lines
369 B
/**
|
|
* Flatten an array into the supplied array.
|
|
*
|
|
* @module reduce-flatten
|
|
* @example
|
|
* const flatten = require('reduce-flatten')
|
|
*/
|
|
module.exports = flatten
|
|
|
|
/**
|
|
* @alias module:reduce-flatten
|
|
* @example
|
|
* > numbers = [ 1, 2, [ 3, 4 ], 5 ]
|
|
* > numbers.reduce(flatten, [])
|
|
* [ 1, 2, 3, 4, 5 ]
|
|
*/
|
|
function flatten (prev, curr) {
|
|
return prev.concat(curr)
|
|
}
|
|
|