Created
March 1, 2019 20:04
-
-
Save cwallenpoole/4128402f0f023a4f866432815561bd68 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
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