22 lines
381 B
JavaScript
22 lines
381 B
JavaScript
'use strict'
|
|
|
|
/**
|
|
* Flatten an array into the supplied array.
|
|
*
|
|
* @module reduce-flatten
|
|
* @example
|
|
* var 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)
|
|
}
|