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
function lowest(arr) {
let min = Number.MAX_VALUE
for (let i = 0; i < arr.length; i++) {
let mean = 0
for (let j = 0; j < arr[i].length; j++) {
mean += arr[i][j]
}
mean /= arr[i].length
if (min > mean) {
min = mean
}
}
return min
}
const myArray = [{
id: 1,
cost: 200
}, {
id: 2,
cost: 1000
}, {
id: 3,
cost: 50
}, {
id: 4,
cost: 500
}]
const min = Math.min(...myArray.map(item => item.cost))
const max = Math.max(...myArray.map(item => item.cost));
console.log(min);
console.log(max);