MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Math › min
Math.min() - JavaScript | MDN
console.log(Math.min(2, 3, 1)); // Expected output: 1 console.log(Math.min(-2, -3, -1)); // Expected output: -3 const array = [2, 3, 1]; console.log(Math.min(...array)); // Expected output: 1
W3Schools
w3schools.com › jsref › jsref_min.asp
JavaScript Math min() Method
The Math.min() method returns the number with the lowest value.
Videos
00:56
JavaScript Math min() method - JavaScript Tutorial for Beginners ...
05:23
How to Find Maximum and Minimum in an Array in JavaScript ...
01:00
JavaScript Methods | Math.min() and Math.max() - YouTube
00:59
Javascript weird parts,Math.min() vs Math.max()#javascript #coding ...
TutorialsPoint
tutorialspoint.com › javascript › math_min.htm
JavaScript Math.min() Method
<html> <body> <script> let number = Math.min(5, 15, 25, 55, 100); document.write("lowest number: ", number); </script> </body> </html> As we can see the output, the lowest number will be "5". In this example, we are passing the array as an argument ...
Programiz
programiz.com › javascript › library › math › min
JavaScript Math min()
// min() with a spread operator let minNum = Math.min(...numbers); console.log(minNum); // Output: 1 · In the above example, we have created an array named numbers.
TechOnTheNet
techonthenet.com › js › math_min.php
JavaScript: Math min() function
In this example, the first output to the console log returned 5 which is the smallest of the values 5 and 10. The second output to the console log returned 20 which is the smallest of the values 60, 40 and 20. The third output to the console log returned -12 which is the smallest of the values ...
Scaler
scaler.com › home › topics › math min() javascript function
Math min() JavaScript Function - Scaler Topics
May 4, 2023 - There will be multiple instances when we have to find out the minimum of two or more numbers (any type). In Javascript programming, we can use the inbuilt Math.min() function to return the smallest number in a set of numbers (there can be
LaunchCode
education.launchcode.org › intro-to-professional-web-dev › appendices › math-method-examples › max-and-min-examples.html
Math.max and Math.min Examples — Introduction to Professional Web Development in JavaScript documentation
Math.min(x, y, z, ...) This method finds and returns the smallest value from a set of numbers (x, y, z,...). To find the minimum value in an array, see below. Example · console.log(Math.min(2, 3, 100.01, 0, -5.2, 100)); Console Output · -5.2 · Unfortunately, the max and min methods will ...
Math.js
mathjs.org › docs › reference › functions › min.html
math.js | an extensive math library for JavaScript and Node.js
Examples · Compute the minimum value of a matrix or a list of values. In case of a multidimensional array, the minimum of the flattened array will be calculated. When dim is provided, the minimum over the selected dimension will be calculated. Parameter dim is zero-based. math.min(a, b, c, ...
Reality Ripple
udn.realityripple.com › docs › Web › JavaScript › Reference › Global_Objects › Math › min
Math.min() - JavaScript
This finds the min of x and y and assigns it to z: ... Math.min() is often used to clip a value so that it is always less than or equal to a boundary.
Reintech
reintech.io › blog › tutorial-applying-math-min-method
Applying the Math.min() Method | Reintech media
February 22, 2023 - Choose Math.min() for clarity with small datasets, reduce() for large arrays, and manual iteration when you need additional processing during comparison. For teams seeking experienced developers who write efficient, maintainable JavaScript code, Reintech connects you with vetted JavaScript developers who understand these performance considerations and best practices.
Top answer 1 of 7
15
Here is the Math.max code in Chrome V8 engine.
function MathMax(arg1, arg2) { // length == 2
var length = %_ArgumentsLength();
if (length == 2) {
arg1 = TO_NUMBER(arg1);
arg2 = TO_NUMBER(arg2);
if (arg2 > arg1) return arg2;
if (arg1 > arg2) return arg1;
if (arg1 == arg2) {
// Make sure -0 is considered less than +0.
return (arg1 === 0 && %_IsMinusZero(arg1)) ? arg2 : arg1;
}
// All comparisons failed, one of the arguments must be NaN.
return NaN;
}
var r = -INFINITY;
for (var i = 0; i < length; i++) {
var n = %_Arguments(i);
n = TO_NUMBER(n);
// Make sure +0 is considered greater than -0.
if (NUMBER_IS_NAN(n) || n > r || (r === 0 && n === 0 && %_IsMinusZero(r))) {
r = n;
}
}
return r;
}
Here is the repository.
2 of 7
7
Below is how to implement the functions if Math.min() and Math.max() did not exist.
Functions have an arguments object, which you can iterate through to get its values.
It's important to note that Math.min() with no arguments returns Infinity, and Math.max() with no arguments returns -Infinity.
function min() {
var result= Infinity;
for(var i in arguments) {
if(arguments[i] < result) {
result = arguments[i];
}
}
return result;
}
function max() {
var result= -Infinity;
for(var i in arguments) {
if(arguments[i] > result) {
result = arguments[i];
}
}
return result;
}
//Tests
console.log(min(5,3,-2,4,14)); //-2
console.log(Math.min(5,3,-2,4,14)); //-2
console.log(max(5,3,-2,4,14)); //14
console.log(Math.max(5,3,-2,4,14)); //14
console.log(min()); //Infinity
console.log(Math.min()); //Infinity
console.log(max()); //-Infinity
console.log(Math.max()); //-Infinity
W3Schools
w3schools.com › js › js_math.asp
JavaScript Math Object
Math.min(0, 150, 30, 20, -8, -200); Try it Yourself »
GitHub
github.com › mdn › content › blob › main › files › en-us › web › javascript › reference › global_objects › math › min › index.md
content/files/en-us/web/javascript/reference/global_objects/math/min/index.md at main · mdn/content
{{InteractiveExample("JavaScript Demo: Math.min()")}} · ```js interactive-example · console.log(Math.min(2, 3, 1)); // Expected output: 1 · · console.log(Math.min(-2, -3, -1)); // Expected output: -3 · · const array = [2, 3, 1]; · ...
Author mdn
Javatpoint
javatpoint.com › javascript-math-min-method
JavaScript Math min() Method - javatpoint
Example 1 Let's see... ... JavaScript The JavaScript math floor() method decreases the given number up to the closest integer value and returns it. If the given number is already an integer, the floor() method returns it directly. Syntax The floor() method is represented by the following syntax: ...