This file contains hidden or 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
// 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 |