Skip to content

max

Returns the largest of the given numbers. Like sum, it accepts either n arguments or a single array of numbers.

Values that are not numbers are skipped, as they are in sum, and so is NaN, which would otherwise win by losing every comparison it takes part in.

When nothing is left to compare — an empty array, or no arguments at all — nullNone is returned.

When nothing is left to compare — an empty list, or no arguments at all — None is returned.

Parameters

NameTypeRequiredDefault
numbers...number[]List<int>*int
The numbers to compare, either as n arguments or as a single array.

Returns

number | null

num?

int | None

Examples

javascript
max(1, 2, 3); // Returns 3
max([4, 2, 8, 6]); // Returns 8
max(-4, -2, -8); // Returns -2
max([]); // Returns null
dart
max([1, 2, 3]); // Returns 3
max([4, 2, 8, 6]); // Returns 8
max([-4, -2, -8]); // Returns -2
max([]); // Returns null
python
max(1, 2, 3)  # Returns 3
max([4, 2, 8, 6])  # Returns 8
max(-4, -2, -8)  # Returns -2
max([])  # Returns None

Released under the MIT License