Created
November 28, 2017 22:07
-
-
Save Ivanca/a0f247cf4a9add9958686174bd5ebcf1 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
// Flattens an array, e.g. [[1,2,[[[3]]]],4] => [1, 2, 3, 4] | |
var flattenArray = (array) => { | |
let initialValue = []; | |
return array.reduce((result, ele) => { | |
if (Array.isArray(ele)) { | |
let flat = flattenArray(ele); | |
return result.concat(flat); | |
} else { | |
result.push(ele); | |
return result; | |
} | |
}, initialValue); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment