intersect()

The intersect linq operator returns a new linq object containing the elements that exist in both the originating collection and the "second" collection. The "second" collection can be anything that the linq.from() method will accept (e.g., an array, a linq object, etc.).

The intersect operator can take a comparer function that determines whether two elements are equal.
var arr1 = [1, 2, 3, 4, 5];
var arr2 = [3, 4, 5, 6, 7];
var arr3 = ['one', 'two', 'three', 'four'];
var arr4 = ['THREE', 'FOUR', 'FIVE', 'SIX'];

// col1 = [3, 4, 5];
var col1 = $linq(arr1).intersect(arr2).toArray();

// col2 = ['three', 'four']
var col2 = $linq(arr3)
    .intersect(arr4, "(x, y) => x.toLowerCase() == y.toLowerCase()")
    .toArray();

Last edited Dec 18, 2013 at 6:26 PM by battousai999, version 6