From 48775b07d0867f298e78553cde9b5fbafc03549f Mon Sep 17 00:00:00 2001 From: Tomoyuki Hata <7702653+hata6502@users.noreply.github.com> Date: Tue, 25 Jan 2022 11:36:09 +0900 Subject: Fix Math.max() initial value to -Infinity --- files/zh-tw/web/javascript/reference/global_objects/math/max/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'files/zh-tw/web/javascript/reference') diff --git a/files/zh-tw/web/javascript/reference/global_objects/math/max/index.html b/files/zh-tw/web/javascript/reference/global_objects/math/max/index.html index d334c6bc02..a3e994c734 100644 --- a/files/zh-tw/web/javascript/reference/global_objects/math/max/index.html +++ b/files/zh-tw/web/javascript/reference/global_objects/math/max/index.html @@ -55,7 +55,7 @@ Math.max(-10, 20); // 20
var arr = [1,2,3]; var max = arr.reduce(function(a, b) { return Math.max(a, b); -}); +}, -Infinity);
The following function uses {{jsxref("Function.prototype.apply()")}} to get the maximum of an array. getMaxOfArray([1, 2, 3])
is equivalent to Math.max(1, 2, 3)
, but you can use getMaxOfArray()
on programmatically constructed arrays. This should only be used for arrays with relatively few elements.