find max value in javascript
//get min/max value of arrays
function getArrayMax(array){
return Math.max.apply(null, array);
}
function getArrayMin(array){
return Math.min.apply(null, array);
}
var ages=[11, 54, 32, 92];
var maxAge=getArrayMax(ages); //92
var minAge=getArrayMin(ages); //11x = findMax(1, 123, 500, 115, 44, 88);
function findMax() {
var i;
var max = -Infinity;
for (i = 0; i < arguments.length; i++) {
if (arguments[i] > max) {
max = arguments[i];
}
}
return max;
}
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
Also in JavaScript:
- javascript get time ago with moment
- getstaticpaths with redux
- how to connect react to backend
- javscript remove a property
- allow cross origin node
- jquery select a dynamic element
- fonction fleche javascript
- javascript array flat
- How to add multiple classes to a ReactJS Component
- javascript filter array by groups of highest
- js promiseStatus
- javascript to uppercase
- pa mmj portal
- How to make remove buttoon on table using js DOM
- Supported by YAML but not supported by JSON:
- react native textinput not show cursor
- regex special characters javascript
- js months ago
- icon refresh material ui
- javascript count element in array
- single node elasticsearch with enable security basic in docker
- install cypress
- jquery alert
- how to run different node app on server different domains