Skip to content

Instantly share code, notes, and snippets.

@Tombarr
Created March 26, 2019 13:04
Show Gist options
  • Save Tombarr/3c5c2e8418fcf57461f2436e386a484a to your computer and use it in GitHub Desktop.
Save Tombarr/3c5c2e8418fcf57461f2436e386a484a to your computer and use it in GitHub Desktop.
Zip multiple arrays (of equal length) using Symbol.iterator
function zip(...arrs) {
let i = -1;
return {
[Symbol.iterator]() {
return this;
},
next: () => ({
done: ++i === arrs[0].length,
value: arrs.map(arr => arr[i])
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment