Policies & Guidelines

ZIP

Zip two arrays together

Description

Given two arrays, returns an array of arrays, where the first array contains the first items of the source arrays, the second array contains the second items and so on.

If the arrays don't have an equal number of items, the extra items are discarded.

Function signature

ZIP(array1: Array, array2: Array) => Array

Parameter

Description

Array 1

First array to zip

Array 2

Second array to zip

Examples

numbers = [100,3,20,50]
numbers2 = [1,2,3]
strings = ["a","b"]
emptyArray = []

Formula

Return value

ZIP(numbers, numbers2)

[[100,1],[3,2],[20,3]]

ZIP(numbers, strings)

[[100,"a"],[3,"b"]]

ZIP(numbers, emptyArray)

[]