Skip to content

Instantly share code, notes, and snippets.

View emiliano1's full-sized avatar
:octocat:
Working...

Emiliano Qaqi emiliano1

:octocat:
Working...
  • Miami, Florida
View GitHub Profile
@emiliano1
emiliano1 / flatten_array.js
Created April 18, 2017 15:30
flattenArray
// recursive function to flatten an n-level deep array
function flattenArray(array, result = []) {
var arrayLength = array.length;
for (var i = 0; i < arrayLength; i++){
if (array[i] instanceof Array) {
// if item is an Array, call the function recursevely
result.concat(flattenArray(array[i], result));
} else {
// if item is not an Array, simply add it to final result