Created
December 1, 2015 18:27
-
-
Save niksudan/fb2fd1deeca44cea0591 to your computer and use it in GitHub Desktop.
Array flattener [JS]
This file contains 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
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