run tdd, update test cases for flatten.
This commit is contained in:
@ -1 +1,4 @@
|
||||
module.exports = flatten = arr => [].concat(...arr);
|
||||
module.exports = flatten = (arr, depth = 1) =>
|
||||
depth != 1
|
||||
? arr.reduce((a, v) => a.concat(Array.isArray(v) ? flatten(v, depth - 1) : v), [])
|
||||
: arr.reduce((a, v) => a.concat(v), []);
|
||||
Reference in New Issue
Block a user