Skip to content

Instantly share code, notes, and snippets.

@cwallenpoole
Created March 1, 2019 20:04
Show Gist options
  • Save cwallenpoole/4128402f0f023a4f866432815561bd68 to your computer and use it in GitHub Desktop.
Save cwallenpoole/4128402f0f023a4f866432815561bd68 to your computer and use it in GitHub Desktop.
function flatten(input){
const out = [];
function recurse(a){
// This captures all iterators, not just arrays.
if(a[Symbol.iterator]) {
for(let v of a){
recurse(v);
}
}
else {
out.push(a);
}
}
recurse(input);
return out;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment