Zip arrays in JavaScript
Pairs up parallel arrays into tuples, stopping at the shortest.
function zip(...arrays) {
const length = Math.min(...arrays.map((a) => a.length));
return Array.from({ length }, (_, i) =>
arrays.map((array) => array[i]),
);
}
Keywords and builtins used here
ArrayMathconstfromfunctionreturn
The run, in numbers
- Lines
- 6
- Characters to type
- 160
- Tokens
- 61
- Three-star pace
- 90 tpm
At the three-star pace of 90 tokens a minute, this run takes about 41 seconds.
Step 7 of 10 in Arrays, step 23 of 43 in Language basics.