Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. const flattenArr = ([head, ...tail], resultingArray) =>
  2. (head === undefined) // When there is no more input array
  3. ? resultingArray // send back the result
  4. : (Array.isArray(head)) // Else is the head an array
  5. ? flattenArr([...head, ...tail])
  6. : flattenArr(tail, [...resultingArray, head])
  7.  
  8. const flatten = (n) => flattenArr(n, []);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement