min()

The min linq operator returns either (1) the minimum element in the collection or (2) the minimum value projected from the elements of the collection by the "selector" function. If the collection is empty, an exception is thrown.
var arr1 = [1, 2, 3, 4, 5];

var arr2 = [{name: 'john', age: 23},
    {name: 'amy', age: 18},
    {name: 'paul', age: 46}];

// val1 = 1
var val1 = $linq(arr1).min();

// val2 = 18
var val2 = $linq(arr2).min("x => x.age");

minBy()

The minBy linq operator returns the element in the collection with the minimum value projected by the "selector" function. If the collection is empty, an exception is thrown.
var arr = [{name: 'john', age: 23},
    {name: 'amy', age: 18},
    {name: 'paul', age: 46}];

// val = {name: 'amy', age: 18}
// note: min() in the previous example returned "18" while 
// minBy() returns the object with age = 18
var val = $linq(arr2).minBy("x => x.age");

max()

The max linq operator returns either (1) the maximum element in the collection or (2) the maximum value projected from the elements of the collection by the "selector" function. If the collection is empty, an exception is thrown.
var arr1 = [1, 2, 3, 4, 5];

var arr2 = [{name: 'john', age: 23},
    {name: 'amy', age: 18},
    {name: 'paul', age: 46}];

// val1 = 5
var val1 = $linq(arr1).max();

// val2 = 46
var val2 = $linq(arr2).max("x => x.age");

maxBy()

The maxBy linq operator returns the element in the collection with the maximum value projected by the "selector" function. If the collection is empty, an exception is thrown.
var arr = [{name: 'john', age: 23},
    {name: 'amy', age: 18},
    {name: 'paul', age: 46}];

// val = {name: 'paul', age: 46}
// note: max() in the previous example returned "46" while 
// maxBy() returns the object with age = 46
var val = $linq(arr2).maxBy("x => x.age");

Last edited Sep 19, 2012 at 5:57 AM by battousai999, version 4