I am using the Math.max function but it is not available on all devices and browsers. Is there a Polyfill or an other easy and fast way to solve this?
Asked
Active
Viewed 667 times
-2
-
4What device doesn't support this? Its been part of JavaScript since forever.. would be surprised that there is a browser that doesn't support it. – putvande Nov 03 '16 at 19:26
-
1[MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max) says this is supported by all browsers. – chazsolo Nov 03 '16 at 19:27
-
1Should be supported in all browser, `Math.max` has been a part of javascript since the first edition ? – adeneo Nov 03 '16 at 19:28
-
It's trivial to write your own max function, if your mysterious device doesn't support `Math.max` for some reason. – Nov 03 '16 at 19:29
-
i am developing an cordova app and there on a samsung galaxy s4 mini the function is not supportet – Tim Jansen Nov 03 '16 at 20:07
-
i used Math.max(...array) – Tim Jansen Nov 03 '16 at 20:07
-
Thats not a problem with `Math.max` but with destructuring (the 3 dots). – putvande Nov 03 '16 at 20:37
3 Answers
0
According to Mozilla Math.max has full browser and mobile support.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max

Eric Kambestad
- 139
- 6
0
See the following code:
if (!Math.max)
{
Math.max = function()
{
var max = Infinity * -1;
for (var index = 0; index < arguments.length; index++)
{
var val = arguments[index];
if (val > max)
{
max = val;
}
}
return max;
};
}

vbguyny
- 1,170
- 1
- 10
- 29
0
The problem you have is not with Math.max
as this has been supported since forever. It is with destructuring (...
in Math.max(...array)
). To get around that you can use older JavaScript which is quite likely supported.
Try :
Math.max.apply(null, array);
(which does pretty much the same as Math.max(...array)
.

putvande
- 15,068
- 3
- 34
- 50