Skip to content

Instantly share code, notes, and snippets.

View ccerrato147's full-sized avatar

Carlos Rene ccerrato147

View GitHub Profile
@ccerrato147
ccerrato147 / flatArray.js
Created January 17, 2017 06:11
Flat an Array
// The nested array
const nested = [[1,2,[3,[8,10]]],4];
// An array that will contain the flatten array
const flat = [];
// The function that runs through the array and flattens it
const scan = (el, arr) =>{
if(!Array.isArray(el))
throw "The first parameter should be an array";
if(!Array.isArray(arr))
throw "The second parameter should be an array";