Skip to content

Instantly share code, notes, and snippets.

@Exlord
Last active September 16, 2016 14:12
Show Gist options
  • Save Exlord/655d032d347a339cb64c96c22c22f077 to your computer and use it in GitHub Desktop.
Save Exlord/655d032d347a339cb64c96c22c22f077 to your computer and use it in GitHub Desktop.
if(!Array.prototype.isArray){
Array.prototype.isArray = function (variable) {
return variable.constructor === Array;
}
}
function flatten(arr, result) {
result = result || [];
for (let i = 0, length = arr.length; i < length; i++) {
var value = arr[i];
if (Array.isArray(value)) {
for (var j = 0, length2 = value.length; j < length2; j++) {
var value2 = value[j];
if (Array.isArray(value2)) {
flatten(value2, result)
} else {
result.push(value2)
}
}
} else {
result.push(value)
}
}
return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment