lodash deinterleave
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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