This project is read-only.

union()

The union linq operator returns a new linq object containing all of the elements in the initial collection and all of the elements in the "second" collection with extra duplicates excluded. The "second" collection can be anything that the linq.from() method will accept (e.g., an array, a linq object, etc.).

A comparer function can also be given that will detemine whether elements are "duplicates".
var arr1 = [1, 2, 3, 4, 5];
var arr2 = ['one', 'two', 'three', 'four'];

// col1 = [6, 7, 8, 9, 10];
var col1 = $linq(arr1).select("x => x + 5");

// col2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
var col2 = $linq(arr1).union(col1).toArray();

// col3 = ['one', 'two', 'three', 'four', 'FIVE', 'SIX']
var col3 = $linq(arr2).union(["THREE", "FOUR", "FIVE", "SIX"], 
    "(x, y) => x.toLowerCase() == y.toLowerCase()")
    .toArray();

Last edited Dec 18, 2013 at 7:27 PM by battousai999, version 4