Last active
August 29, 2015 14:08
-
-
Save Shahor/cbaa575636b33b797477 to your computer and use it in GitHub Desktop.
write a function that takes an array as input that can contain both ints and more arrays (which can also contain an array or int) and return the flattened array.
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) { | |
var ret = [] | |
input.forEach(function (inp) { | |
ret = ret.concat(Array.isArray(inp) ? flatten(inp) : inp) | |
}) | |
return ret | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment