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
// Create our array-flattening method (using a recursive approach) | |
const flatten = (arr) => { | |
// Return a new flattened array | |
return arr.reduce((prev, next) => { | |
// Make sure we have an array to add items to | |
prev = Array.isArray(prev) ? prev : [prev] | |
// If the next element in `arr` is not an array, add it to our flattened array |