Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export default function flattenDeeplyNestedArray(array) {
- return array.reduce((flattenedArray, value) => {
- if (Array.isArray(value)) {
- // If our value is an array itself, flatten again before concating
- return flattenedArray.concat(flattenDeeplyNestedArray(value))
- } else {
- // Otherwise simply concat it to the reducing array
- return flattenedArray.concat(value)
- }
- }, [])
- }
Add Comment
Please, Sign In to add comment