Skip to content

Instantly share code, notes, and snippets.

@bishil06
Created February 9, 2021 02:12
Show Gist options
  • Select an option

  • Save bishil06/7a39458e302c6a2ebe2eb2dd646c2e9f to your computer and use it in GitHub Desktop.

Select an option

Save bishil06/7a39458e302c6a2ebe2eb2dd646c2e9f to your computer and use it in GitHub Desktop.
_JavaScript_zip_iterable
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