Skip to content

Instantly share code, notes, and snippets.

@oklandon
oklandon / flatten.js
Created November 8, 2019 05:58
flatten array
// loops through the array recursively and appends items until the 'current' list item is not an array
const flatsy = (arr, carry=[]) =>
Array.isArray(arr) ? arr.reduce((acc, curr) =>
Array.isArray(curr)
? flatsy(curr, acc)
: [...acc, curr]
,
carry
) : arr

Keybase proof

I hereby claim:

  • I am oklandon on github.
  • I am pl_oklandon (https://keybase.io/pl_oklandon) on keybase.
  • I have a public key ASCZv0P_6O5DvMjX7skq-vruFrUkLLRA2Ol8xwHhsjuhWgo

To claim this, I am signing this object: