Created
August 15, 2019 16:53
-
-
Save fcpauldiaz/ed474f54de006f5b9b69020b6cc64b5d to your computer and use it in GitHub Desktop.
This file contains 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
function flatten (array) { | |
// check that input is an array | |
if (array.constructor === Array) { | |
return array.reduce((accum, currentValue) => { | |
if (array.constructor === Array) { | |
// flatten the array using es6 reducer | |
return accum.concat(currentValue.reduce(flatten, [])) | |
} else { | |
// append/concat | |
return accum.concat(currentValue) | |
} | |
} | |
, [] | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment