arrayMax

arrayMax

> Functions

Returns the element with the maximum value of the array array. For more information about the maximum value of an array see sort.

Parameters
Return
TypeScript

In JavaScript, Math.max(...a) returns -Infinity on an empty array, where arrayMax returns null, and NaN as soon as an element is not a number — strings are not ordered alphabetically as in LeekScript. Above all, the ... spread is limited to about 65,000 arguments: beyond that, Math.max(...a) raises a RangeError. On a large array, write a.reduce((m, x) => x > m ? x : m) instead.

Python

In Python, max() raises a ValueError on an empty list, where arrayMax returns null: pass default to get that behaviour back, max(a, default=None). The comparison is Python's and not LeekScript's order: a list mixing numbers and strings raises a TypeError instead of ordering them. max also accepts a key, max(a, key=lambda e: e.life), and then returns the element, not the key's value.