This project is read-only.

intersect(second[, comparer, arg])

Produces the set intersection of two sequences by using the specified equality comparer to compare values.

Syntax

Parameters

second
An iteratable object whose distinct elements that also appear in the first sequence will be returned.
comparer
Type: function(value1, value2, arg): boolean
An equality comparer to compare values.
arg
An external argument.
Return Value

A sequence that contains the elements that form the set intersection of two sequences.

Examples

var id1 = [ 44, 26, 92, 30, 71, 38 ];
var id2 = [ 39, 59, 83, 47, 26, 4, 30 ];

var both = $from(id1).intersect(id2);

both.each("document.writeln($)");

/*
 This code produces the following output:

 26
 30
*/

var store1 = [ { name: "apple", code: 9 }, 
               { name: "orange", code: 4 } ];

var store2 = [ { name: "apple", code: 9 }, 
               { name: "lemon", code: 12 } ];

// Get the products from the first array 
// that have duplicates in the second array.

var comparer = "#0 == #1 || (#0 && #1 && #0.name == #1.name && #0.code == #1.code)";

var duplicates = 
    $from(store1).intersect(store2, comparer);

duplicates.each("document.writeln($name + ' ' + $code)");

/*
    This code produces the following output:
    apple 9
*/

Last edited May 16, 2012 at 2:50 PM by suckgamoni, version 1

Comments

No comments yet.