Last active
September 16, 2016 14:12
-
-
Save Exlord/655d032d347a339cb64c96c22c22f077 to your computer and use it in GitHub Desktop.
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
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