Created
February 10, 2020 16:34
-
-
Save exbotanical/2a350177d7677eea2968eb4f176431ec to your computer and use it in GitHub Desktop.
zip an object of arrays js
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
// 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