Skip to content

Instantly share code, notes, and snippets.

// 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