Answers for "javascript min max"

17

max value in array javascript

// For large data, it's better to use reduce. Supose arr has a large data in this case:
const arr = [1, 5, 3, 5, 2];
const max = arr.reduce((a, b) => { return Math.max(a, b) });

// For arrays with relatively few elements you can use apply: 
const max = Math.max.apply(null, arr);

// or spread operator:
const max = Math.max(...arr);
Posted by: Guest on November-27-2020
1

min and max javascript

Math.max(1, 2, 3)    // 3
Math.min(1, 2, 3)    // 1

var nums = [1, 2, 3]
Math.min(...nums)    // 1
Math.max(...nums)    // 3
Posted by: Guest on April-05-2021
13

math.max in javascript

Math.max() function returns the largest of the zero or more numbers given as input parameters.
Math.max(1,10,100); // return 100
Posted by: Guest on December-31-2020
1

how to return the max and min of an array in javascript

function minMax(arr) {
  return [Math.min(...arr), Math.max(...arr)];
}
Posted by: Guest on April-09-2020
1

js return the highest and lowest number

console.log(Math.max(1, 3, 2));
// expected output: 3

console.log(Math.max(-1, -3, -2));
// expected output: -1

const array1 = [1, 3, 2];

console.log(Math.max(...array1));
// expected output: 3
Posted by: Guest on July-09-2020
0

javascript index of biggest number

arr.indexOf(Math.max(...arr))
Posted by: Guest on December-20-2019

Code answers related to "javascript min max"

Code answers related to "Javascript"

Browse Popular Code Answers by Language