Skip to content

Instantly share code, notes, and snippets.

@exbotanical
Created February 10, 2020 16:34
Show Gist options
  • Save exbotanical/2a350177d7677eea2968eb4f176431ec to your computer and use it in GitHub Desktop.
Save exbotanical/2a350177d7677eea2968eb4f176431ec to your computer and use it in GitHub Desktop.
zip an object of arrays js
// zip object of arrays: { [],[], ... } -> [ arr1[0] + arr2[0] ], [ arr1[1], arr2[1], ... ]
const zip = (arrays) => {
return arrays[0].map(function(_,i){
return arrays.map(function(array){return array[i]})
})
}
// e.g.
// stateArray = Object.values(this.context.state).map(i => stateArray.concat(i))
// stateArray = this.zip(stateArray)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment