Repository URL to install this package:
|
Version:
6.0.4 ▾
|
/**
* @TODO move this
* @TODO support collections
* @memberOf util
*
* Creates a new list out of the two supplied by pairing up equally-positioned
* items from both lists. The returned list is truncated to the length of the
* shorter of the two input lists.
* Note: `zip` is equivalent to `zipWith(function(a, b) { return [a, b] })`.
*
* @param {Array} list1 The first array to consider.
* @param {Array} list2 The second array to consider.
* @return {Array} The list made by pairing up same-indexed elements of `list1` and `list2`.
*
* @fork v0.1.0
* @category List
* @sig [a] -> [b] -> [[a,b]]
* @symb R.zip([a, b, c], [d, e, f]) = [[a, d], [b, e], [c, f]]
*
* @example
*
* zip([1, 2, 3], ['a', 'b', 'c']);
* //=> [[1, 'a'], [2, 'b'], [3, 'c']]
*
*/
export default function zip(a, b) {
const result = []
let idx = 0
const len = Math.min(a.length, b.length)
while (idx < len) {
result[idx] = [a[idx], b[idx]]
idx += 1
}
return result
}