Praktikum_mf

Untitled

Apr 19th, 2021
566
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.25 KB | None | 0 0
  1. function flatten(list) {
  2. newList = []
  3. for (el of list) {
  4. if (!Array.isArray(el))
  5. newList.push(el)
  6. if (Array.isArray(el)) {
  7. for (e of el) {
  8. if (!Array.isArray(e)) {
  9. newList.push(e)
  10. }
  11. else for (i of e) {
  12. newList.push(i)
  13. }
  14. }
  15. }
  16. }
  17. return newList
  18. }
Advertisement
Add Comment
Please, Sign In to add comment