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
1Math.max(1, 2, 3) // 3
2Math.min(1, 2, 3) // 1
3
4var nums = [1, 2, 3]
5Math.min(...nums) // 1
6Math.max(...nums) // 3
1const dates = [];
2dates.push(new Date('2011/06/25'));
3dates.push(new Date('2011/06/26'));
4dates.push(new Date('2011/06/27'));
5dates.push(new Date('2011/06/28'));
6const maxDate = new Date(Math.max.apply(null, dates));
7const minDate = new Date(Math.min.apply(null, dates));
1int max;
2max=INT_MIN;
3
4for(int i=0;i<ar.length();i++){
5 if(ar[i]>max){
6 max=ar[i];
7 }
8
9
1var numbers = [1, 2, 3, 4];
2Math.max(...numbers) // 4
3Math.min(...numbers) // 1