Skip to content

Instantly share code, notes, and snippets.

@AncyentMariner
Last active December 6, 2016 02:54
Show Gist options
  • Save AncyentMariner/2a6fefee42c476867a9b587ea08c82fe to your computer and use it in GitHub Desktop.
Save AncyentMariner/2a6fefee42c476867a9b587ea08c82fe to your computer and use it in GitHub Desktop.
Flatten an array in javascript
//Write some code, that will flatten an array of arbitrarily nested arrays of integers into a flat array of integers.
//e.g. [[1,2,[3]],4] -> [1,2,3,4].
const flatten_list = list => list.reduce(
(a, b) => a.concat(Array.isArray(b) ? flatten_list(b) : b), []
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment