Created
April 10, 2017 21:55
-
-
Save waleedsamy/79dd535e0f51dd034625ebfe098ce197 to your computer and use it in GitHub Desktop.
flatten [1, [2], 3, [4, 5, [6, 7, [8, 9, 10]]]] => [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const flatten = arr => arr.reduce( | |
(acc, val) => acc.concat(Array.isArray(val) ? flatten(val) : val), [] | |
); | |
module.exports = { | |
flatten: flatten | |
} | |
// let list = [1, [2], 3, [4, 5, [6, 7, [8, 9, 10]]]] | |
// console.log(flatten(list)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment