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
1var arr = [1, 2, 3];
2var max = arr.reduce(function(a, b) {
3 return Math.max(a, b);
4});
1function getMaxOfArray(numArray) {
2 return Math.max.apply(null, numArray);
3}
1const maxMinArray = (a,b,...c) =>{
2 //we are concatinating this array
3 let array = [a,b];
4 let newArray = array.concat(c);
5 //now let's get started with the excersice
6 let max = 0;
7 for(let number of newArray){
8 if(max<number){
9 max = number;
10 }
11 }
12 let min = max;
13 for(let number of newArray){
14 if(number<min){
15 min = number;
16 }
17 }
18 return console.log(max + ' ' + min)
19}
20//example:
21maxMinArray(12,14,15,23)
22