Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

zip(second, resultSelector[, arg])

suckgamoni edited this page · 1 revision

Filters a sequence of values based on a predicate.

Syntax

Parameters

second

The second input sequence.

resultSelector

Type: function(value1, value2, key1, key2, arg)
A function that specifies how to combine the corresponding elements of the two sequences.

arg

An external argument.

Return Value

An iterable object that contains elements of the two input sequences, combined by resultSelector.


Example

var numbers = [ 1, 2, 3, 4 ];
var words = [ "one", "two", "three" ];

// The following example concatenates corresponding elements of the
// two input sequences.
var numbersAndWords = from(numbers).zip(words, "#0 + ' ' + #1");
numbersAndWords.each("console.log($)");

// The following example returns the larger element from each 
// corresponding pair in the input sequences.
var numbers2 = [ 5, 2, 1, 3, 6 ];
var largerElements = from(numbers2).zip(numbers, "#0 > #1 ? #0 : #1");
largerElements.each("console.log($)");

// The following example calculates the commission that is earned by 
// an employee who had sales in the first three quarters of the year.
var quarterlySales = [ 4023.52, 7701.65, 2435.20 ];
var quarterlyRate = [ 0.25, 0.2, 0.3, 0.2 ];
var totalCommission = from(quarterlySales).zip(quarterlyRate, "#0 * #1").sum();
console.log(totalCommission);

// Output:
// 1 one
// 2 two
// 3 three

// 5
// 2
// 3
// 4

// 3276.77
Something went wrong with that request. Please try again.