Skip to content

Instantly share code, notes, and snippets.

@nrkn
Created May 30, 2017 22:17
Show Gist options
  • Save nrkn/34966cdb710d7b3585d9fc056d659219 to your computer and use it in GitHub Desktop.
Save nrkn/34966cdb710d7b3585d9fc056d659219 to your computer and use it in GitHub Desktop.
const flatten = array => {
const result = []
const nodes = array.slice()
let node
while( nodes.length > 0 ){
node = nodes.pop()
if( Array.isArray( node ) ){
nodes.push( ...node )
} else {
result.unshift( node )
}
}
return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment