Skip to content

Instantly share code, notes, and snippets.

View Markues's full-sized avatar

Jeff Farris Markues

  • New York City
View GitHub Profile
@Markues
Markues / arrayFlatten.js
Created May 11, 2016 15:47
Function to flatten a nested array using recursion (ES6)
// If the flatten function is not already defined
if(typeof Array.prototype.flatten !== "function") {
Array.prototype.flatten = function() {
let newArray = [];
this.forEach((current, index, array) => {
// If the current item is an array
if(current.constructor === Array) {
// Recursively call flatten on that item and concatenate
// it to our final array
newArray = newArray.concat(current.flatten());