linq.Max

Gets the maximum value in an array

Overloads

  • Object Max ()
  • Object Max (selector)
  • Object Max (selector, comparator)

Object Max ()

Gets the maximum value found in the array, using the default comparator

Example

var myArray = [1,3,4,4,4,5];
//Returns 5
myArray.Max();

Object Max (selector)

Gets the element in the array having the maximum value of the selected property, using the default comparator

Example

var myArray = [{x: 1}, {x: 3}, {x: 4}, {x: 4}, {x: 4}, {x: 5}];
//Returns {x: 5}
myArray.Max("o=>o.x");

Object Max (selector, comparator)

Gets the element in the array having the maximum value of the selected property, using the specified comparator

Example

var myArray = [{x: "Hi"}, {x: "Hello"}, {x: "Hello There!"}];
//Returns {x: "Hello There!"}
myArray.Max("o=>o.x", "(a, b) => a.length > b.length ? 1 : a.length < b.length ? -1 : 0");

Last edited Sep 24, 2011 at 4:41 AM by mlorbetske, version 1

Comments

No comments yet.