How to find max and min of a subset of an array in JavaScript

1 Answer

0 votes
const arr = [1, 3, 7, 9, 2, 8, 5, 4];
 
const max = Math.max(...arr.slice(1, 5)); // [ 3, 7, 9, 2 ]
console.log(max);
 
const min = Math.min(...arr.slice(1, 5));
console.log(min);
 
 
 
/*
run:
 
9
2
 
*/

 



answered Jul 20, 2024 by avibootz
edited Jul 20, 2024 by avibootz
...