Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const flatten = (arr) => {
- const res = [];
- arr.forEach(item => {
- if (typeof item == 'number') {
- res.push(item)
- } else {
- res.push(...flatten(item))
- }
- })
- return res;
- }
- console.log(flatten([[[1,2]],[3],[[4]]]))
Add Comment
Please, Sign In to add comment