Created
February 9, 2021 02:12
-
-
Save bishil06/7a39458e302c6a2ebe2eb2dd646c2e9f to your computer and use it in GitHub Desktop.
_JavaScript_zip_iterable
This file contains hidden or 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(iter1, iter2) { | |
| const a = iter1[Symbol.iterator](); | |
| const b = iter2[Symbol.iterator](); | |
| let va = null; | |
| let vb = null; | |
| while (!((va = a.next()).done) && !((vb = b.next()).done)) { | |
| yield [va.value, vb.value]; | |
| } | |
| } | |
| for(const a of zip([1,2,3], [10, 20, 30])) console.log(a); | |
| /* | |
| console.log | |
| [ 1, 10 ] | |
| [ 2, 20 ] | |
| [ 3, 30 ] | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment