Skip to content

Instantly share code, notes, and snippets.

@rmemory
rmemory / flatten_nested_array.js
Created December 11, 2018 22:10
Flatten an array of arbitrarily nested arrays.
/**
* Flatten an array of arbitrarily nested arrays. For example,
*
* [[1,2,[3]],4] -> [1,2,3,4]
*
* It will flatten nested arrays containing not only integer data, but any data.
*
* Caveat: It does operate recursively, so make sure the nested array fits
* within the capabilities of your stack.
*