run tdd, update test cases for flatten.

This commit is contained in:
Stefan Feješ
2018-01-11 09:51:49 +01:00
parent 41001626c7
commit ce4540f71d
3 changed files with 6 additions and 1 deletions

View File

@ -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), []);