Created
March 26, 2019 13:04
-
-
Save Tombarr/3c5c2e8418fcf57461f2436e386a484a to your computer and use it in GitHub Desktop.
Zip multiple arrays (of equal length) using Symbol.iterator
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
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