Guest User

Untitled

a guest
Oct 23rd, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. export default function flattenDeeplyNestedArray(array) {
  2.  
  3. return array.reduce((flattenedArray, value) => {
  4.  
  5. if (Array.isArray(value)) {
  6.  
  7. // If our value is an array itself, flatten again before concating
  8. return flattenedArray.concat(flattenDeeplyNestedArray(value))
  9.  
  10. } else {
  11.  
  12. // Otherwise simply concat it to the reducing array
  13. return flattenedArray.concat(value)
  14.  
  15. }
  16. }, [])
  17.  
  18. }
Add Comment
Please, Sign In to add comment