1// For large data, it's better to use reduce. Supose arr has a large data in this case:
2const arr = [1, 5, 3, 5, 2];
3const max = arr.reduce((a, b) => { return Math.max(a, b) });
4
5// For arrays with relatively few elements you can use apply:
6const max = Math.max.apply(null, arr);
7
8// or spread operator:
9const max = Math.max(...arr);
10
1function removeSmallest(arr) {
2 var min = Math.min(...arr);
3 return arr.filter(e => e != min);
4}
1const arr = [14, 58, 20, 77, 66, 82, 42, 67, 42, 4]
2const min = Math.min(...arr)
3console.log(min)
1//Not using Math.min:
2const min = function(numbers) {
3 let smallestNum = numbers[0];
4for(let i = 1; i < numbers.length; i++) {
5 if(numbers[i] < smallestNum) {
6 smallestNum = numbers[i];
7 }
8 }
9return smallestNum;
10};
1var arr = [5,1,9,5,7];
2var smallest = arr[0];
3
4for(var i=1; i<arr.length; i++){
5 if(arr[i] < smallest){
6 smallest = arr[i];
7 }
8}
9
10console.log(smallest);
11