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
// 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()); |