Skip to content

Instantly share code, notes, and snippets.

@KhanMaytok
Forked from the-creature/flatten.js
Created February 1, 2017 04:32
Show Gist options
  • Save KhanMaytok/4b0b23d6c0bf15a55ee29600f48702a1 to your computer and use it in GitHub Desktop.
Save KhanMaytok/4b0b23d6c0bf15a55ee29600f48702a1 to your computer and use it in GitHub Desktop.
es6 flat array
const flatten = arr => arr.reduce(
(a, b) => a.concat(Array.isArray(b) ? flatten(b) : b), []
);
testArr = [[1,2,[3]],4]
console.log(flatten(testArr));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment