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 › home › javascript › javascript math.min() function
Understanding JavaScript Math.min() Function
September 1, 2008 - Following is the syntax of JavaScript Math.min() method − ... This method takes in a random number of parameters. The same is described below − · value1, value2, ... valueN: These are the numeric values for which we want to find the minimum. We can provide multiple values separated by commas. This method returns the largest of the provided numbers. In the following example, we are using the JavaScript Math.min() method to find the minimum among the provided negative numbers −
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 Method Examples · Math.max and Math.min Examples · The general syntax for this method is: Math.max(x, y, z, ...) This method finds and returns the largest value from a set of numbers (x, y, z, ...). To find the maximum value in an array, see below. Example · console.log(Math.max(2, ...
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: ...
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Math
Math - JavaScript | MDN
In JavaScript, we can do this with the following: js · 50 * Math.tan(degToRad(60)); We use our degToRad() function to convert 60 degrees to radians, as Math.tan() expects an input value in radians. This can be achieved with a combination of Math.random() and Math.floor(): js · function ...