max

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

返回 Enumerable 中元素的最大值,若指定 iterator,则使用 iterator 对元素进行处理,并返回处理后的最大值。如果 Enumerable 为空,返回 undefined

注意:对于相等的值,返回最后一个。

可选的 context 参数是 iterator 要绑定的对象,若设定该参数,iterator 中的 this 关键字将指向 context 对象。

样例

$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