Skip to content

Instantly share code, notes, and snippets.

@stockholmux
Last active October 31, 2017 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stockholmux/875ceb41c908b721b154791a01eeed25 to your computer and use it in GitHub Desktop.
Save stockholmux/875ceb41c908b721b154791a01eeed25 to your computer and use it in GitHub Desktop.
lodash deinterleave
const deinterleave = function(doc) { // `doc` is an array like this `['fname','kyle','lname','davis']`
return _(doc) // Start the lodash chain with `doc`
.chunk(2) // `chunk` to convert `doc` to `[['fname','kyle'],['lname','davis']]`
.fromPairs() // `fromPairs` converts paired arrays into objects `{ fname : 'kyle', lname : 'davis }`
.value(); // Stop the chain and return it back
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment