Skip to content

Instantly share code, notes, and snippets.

@Shahor
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shahor/cbaa575636b33b797477 to your computer and use it in GitHub Desktop.
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.
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