Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- const flatten = ([head, ...tail]) => {
- return head === undefined
- ? []
- : ( Array.isArray(head) ? [...flatten(head), ...flatten(tail)] : [head, ...flatten(tail)])
- ;
- }
- flatten([1,[2,3, [4,5]], 6]);
- //=> [1,2,3,4,5,6]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement