Skip to content

zip

Summary

Combine each element at the same index of two arrays.

Tip

This function is curried.

Description

Takes two arrays a and b and returns a new array where each element of a and b at the same index are put together. The length of the new array is equal to the length of the smallest array.

Examples

1
2
zip([1, 2], [10, 20]);
//=> [[1, 10], [2, 20]]

When arrays are not the same length

1
2
3
4
5
6
7
8
zip([1, 2], [10, 20, 30]);
//=> [[1, 10], [2, 20]]
zip([1, 2], [10]);
//=> [[1, 10]]
zip([1, 2], []);
//=> []
zip([], [10, 20, 30]);
//=> []

Parameters

Name Type Description
a Array An array
b Array Another array

Return

Array.<Array>