From cb9e359a51c3249d8f5157db69d43fd413ddeda6 Mon Sep 17 00:00:00 2001 From: Florian Merz Date: Thu, 11 Feb 2021 14:45:12 +0100 Subject: unslug ca: move --- .../reference/global_objects/math/max/index.html | 134 +++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 files/ca/web/javascript/reference/global_objects/math/max/index.html (limited to 'files/ca/web/javascript/reference/global_objects/math/max') diff --git a/files/ca/web/javascript/reference/global_objects/math/max/index.html b/files/ca/web/javascript/reference/global_objects/math/max/index.html new file mode 100644 index 0000000000..791b5dfdfe --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/math/max/index.html @@ -0,0 +1,134 @@ +--- +title: Math.max() +slug: Web/JavaScript/Referencia/Objectes_globals/Math/max +translation_of: Web/JavaScript/Reference/Global_Objects/Math/max +--- +
{{JSRef}}
+ +

La funció Math.max() retorna el nombre més gran de zero o més nombres.

+ +

Sintaxi

+ +
Math.max([valor1[, valor2[, ...]]])
+ +

Paràmetres

+ +
+
valor1, valor2, ...
+
Nombres.
+
+ +

Descripció

+ +

Com que max() és un mètode estàtic de Math, sempre s'utilitza com Math.max() en comptes de com un mètode d'un objecte Math creat (Math no és un constructor).

+ +

Si no es proporciona cap argument, el resultat és -{{jsxref("Infinity")}}.

+ +

Si al menys un dels arguments no pot convertir-se a un nombre, el resultat és {{jsxref("NaN")}}.

+ +

Exemples

+ +

Utilitzar Math.max()

+ +
Math.max(10, 20);   //  20
+Math.max(-10, -20); // -10
+Math.max(-10, 20);  //  20
+
+ +

La següent funció utilitza {{jsxref("Function.prototype.apply()")}} per a trobar l'element màxim d'un array numèric. getMaxOfArray([1, 2, 3]) és equivalent a Math.max(1, 2, 3), però getMaxOfArray() pot emprar-se en arrays de qualsevol mida construits programàticament.

+ +
function getMaxOfArray(numArray) {
+  return Math.max.apply(null, numArray);
+}
+
+ +

O bé amb el nou {{jsxref("Operators/Spread_operator", "operador spread")}}, obtenir el nombre màxim d'un array és molt més simple.

+ +
var arr = [1, 2, 3];
+var max = Math.max(...arr);
+
+ +

Especificacions

+ + + + + + + + + + + + + + + + + + + + + + + + +
EspecificacióEstatComentaris
{{SpecName('ES1')}}{{Spec2('ES1')}}Definició inicial. Implementat a JavaScript 1.0.
{{SpecName('ES5.1', '#sec-15.8.2.11', 'Math.max')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-math.max', 'Math.max')}}{{Spec2('ES6')}} 
+ +

Compatibilitat amb navegadors

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +

Vegeu també

+ + -- cgit v1.2.3-54-g00ecf