Skip to content

Instantly share code, notes, and snippets.

@francoisromain
Last active August 29, 2015 14:21
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 francoisromain/ac23c5ff9b48ec030a9c to your computer and use it in GitHub Desktop.
Save francoisromain/ac23c5ff9b48ec030a9c to your computer and use it in GitHub Desktop.
flatten.js
// flatten an array
// input [[[[1], 2, 3], 4, 5, 6, 7], 8, 9, 10, [11, 12, 13]]
// output [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
var flatten = function(e){
var flatArray = [];
if (!Array.isArray(e)) {
flatArray = flatArray.concat(e);
} else {
for (var i = 0; i < e.length; i++) {
flatten(e[i]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment