Skip to content

Instantly share code, notes, and snippets.

@JamieLottering
Created April 5, 2013 04:09
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 JamieLottering/5316564 to your computer and use it in GitHub Desktop.
Save JamieLottering/5316564 to your computer and use it in GitHub Desktop.
Array Flatten
(function (env, obj) {
var arrayType = '[object Array]';
function flatten (arr) {
var flattened = [];
var i = 0, l = arr.length;
for(; i < l; i++) {
var value = arr[i];
if (obj.toString.call(value) === arrayType) {
flattened = flattened.concat(flatten(value));
} else {
flattened.push(value);
}
}
return flattened;
}
})(this, Object.prototype);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment