Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save BiosBoy/bcc9f065999168942ffb9448dd3932af to your computer and use it in GitHub Desktop.

Select an option

Save BiosBoy/bcc9f065999168942ffb9448dd3932af to your computer and use it in GitHub Desktop.
const flatter = args => {
const arr = [...args]
const arrFlat = []
const _iterator = (arrTemp) => {
arrTemp.forEach(item => item.push ? _iterator(item) : arrFlat.push(item))
return arrFlat
}
return _iterator(arr)
}
const result = flatter([1, 2, [4, 6, 6, [12, 24, [12, 14, [32]]]]])
console.log(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment