max

max([iterator = Prototype.K[, context]]) -> maxValue

Returns the maximum element (or element-based computation), or undefined if the enumeration is empty. Elements are either compared directly, or by first applying the iterator and comparing returned values.

Note: for equivalent elements, the latest one is returned.

The optional context parameter is what the iterator function will be bound to. If used, the this keyword inside the iterator will point to the object given by the argument.

Examples


$R(1,10).max()
// -> 10

['hello', 'world', 'gizmo'].max()
// -> 'world'

function Person(name, age) {
   this.name = name;
   this.age = age;
}

var john = new Person('John', 20);
var mark = new Person('Mark', 35);
var daisy = new Person('Daisy', 22);

[john, mark, daisy].max(function(person) {
  return person.age;
})
// -> 35