OneCompiler

Find largest & smallest value in the array.

336

Find the largest & smallest value in the array

Using Math library

let arr = [1,2,3,4,53,5];
let result = Math.max(...arr);  // min for smallest
console.log(result); 

Not using library

let arr = [1,23,6,3,8,7,5,4];
let bigValue = arr[0];
arr.forEach((val) => {
  if(val > bigValue)  // < for smallest 
    bigValue = val;
})
console.log(bigValue);