Guest User

Untitled

a guest
Jan 19th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.23 KB | None | 0 0
  1. const flatten = (arr) => {
  2. const res = [];
  3. arr.forEach(item => {
  4. if (typeof item == 'number') {
  5. res.push(item)
  6. } else {
  7. res.push(...flatten(item))
  8. }
  9. })
  10. return res;
  11. }
  12.  
  13. console.log(flatten([[[1,2]],[3],[[4]]]))
Add Comment
Please, Sign In to add comment