Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function flatten(list) {
- newList = []
- for (el of list) {
- if (!Array.isArray(el))
- newList.push(el)
- if (Array.isArray(el)) {
- for (e of el) {
- if (!Array.isArray(e)) {
- newList.push(e)
- }
- else for (i of e) {
- newList.push(i)
- }
- }
- }
- }
- return newList
- }
Advertisement
Add Comment
Please, Sign In to add comment