Created
September 4, 2017 21:11
-
-
Save rubentd/0e7ce44f0ae7296d3345a154ad39bdee to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function flatten(a) { | |
let flat = []; | |
for(var item of a){ | |
if(Array.isArray(item)){ | |
flat = flat.concat(flatten(item)); | |
}else{ | |
flat.push(item); | |
} | |
} | |
return flat; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
// To run this use babel-node with e2015 preset
import flatten from './flatten';
let a = [1, [[2], [3]], [4, [5], 6, [[[7, 8, 9]]]]];
console.log(flatten(a));