Skip to content

Instantly share code, notes, and snippets.

@niksudan
Created December 1, 2015 18:27
Show Gist options
  • Save niksudan/fb2fd1deeca44cea0591 to your computer and use it in GitHub Desktop.
Save niksudan/fb2fd1deeca44cea0591 to your computer and use it in GitHub Desktop.
Array flattener [JS]
var flatten = function(array)
{
var result = [];
array.forEach(function(element) {
if (element instanceof Array) {
flatten(element).forEach(function(subElement) {
result.push(subElement);
}, this);
} else {
result.push(element);
}
}, this);
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment