Math.min are some of them.
Math.max(1, 2, 3, 4); // 4
// Doesn't work because it treats the array as a single parameter
// That parameter isn't a number, so the function returns `NaN`
Math.max([1, 2, 3, 4]); // NaN
If we want to pass a dynamic array of numbers, then the ES6 spread operator (
...) can help. It turns a varible to a list of individual parameters:
const array = [1, 2, 3, 4];
Math.max(...array); // 4
... operator doesn't work if you have a big array. Using the
reduce method doesn't have this problem.
const max = arr => arr.reduce((a, b) => Math.max(a, b));
max([1, 2, 3, 4]); // 4