Skip to content

Instantly share code, notes, and snippets.

View trainbolt's full-sized avatar
🎯
Focusing

trainbolt

🎯
Focusing
View GitHub Profile
@trainbolt
trainbolt / nestedFlatten.js
Created May 16, 2019 18:43
Flatten nested arrays
const n = [1,[2,[3,4,5]],6,[7,[8],[9,[10]]]];
const n2 = [1,[2,[3,[4,[5],6],7],8],9];
/**
* Flattens arbitrarilily nested arrays. Pulls off the first item (a) from the array
* and preserves the rest (arr) using the spread operator.
*
* @param {Array} [] The nested array to flatten
* @param {Array} flat The nested array to flatten
* @returns {Array} Recursively returns a flattened array