// For large data, it's better to use reduce. Supose arr has a large data in this case:const arr =[1,5,3,5,2];const max = arr.reduce((a, b)=>{returnMath.max(a, b)});// For arrays with relatively few elements you can use apply: const max =Math.max.apply(null, arr);// or spread operator:const max =Math.max(...arr);
#include <stdio.h>
int main(){
int i, n;
float arr[100];printf("Enter the number of elements (1 to 100): ");scanf("%d",&n);for(i =0; i < n;++i){printf("Enter number%d: ", i +1);scanf("%f",&arr[i]);}// storing the largest number to arr[0]for(i =1; i < n;++i){if(arr[0]< arr[i])
arr[0]= arr[i];}printf("Largest element = %.2f", arr[0]);return0;}
publicstaticvoidmain(String[] args){
int[] xr ={2,4,1,3,7,5,6,10,8,9};//find maximum value
int max = xr[0];for(int i =0; i < xr.length; i++){if(xr[i]> max){
max = xr[i];}}//find minimum value
int min=xr[0];for(int i =0; i <xr.length; i++){if(xr[i]<min){
min=xr[i];}}System.out.println("max: "+max);System.out.println("min: "+min);}
// For regular arrays:var max =Math.max(...arrayOfNumbers);// For arrays with tens of thousands of items: let max = testArray[0];//here we have considered max to the first element because we don't know which is max yet.for(let i =1; i < testArrayLength;++i){if(testArray[i]> max){//in each iteration it will compare if the value is greater than the current considered value (we just considered first element)
max = testArray[i];//in the above iteration if the testArray find value/element greater than max then this new max value will be considered as Max (this will happen until the max value found).}}
functionarrayMin(arr){return arr.reduce(function(p, v){return( p < v ? p : v );});}functionarrayMax(arr){return arr.reduce(function(p, v){return( p > v ? p : v );});}
(function(){const arr =[23,65,3,19,42,74,56,8,88];functionfindMaxArrValue(arr){if(arr.length){let max =-Infinity;for(let num of arr){
max = num > max ? num : max;}return max;}return0;// or any value what you need}console.log(findMaxArrValue(arr));// => 88})();
var myPersons__ =document.querySelectorAll('.avtrlnk');var maxId__ =[];for(var x =0; x < myPersons__.length;++x){
maxId__[x]= myPersons__[x].value;}
myPersons__ =parseInt(maxId__.sort()[x-1])+1;
constfindMax=(arr)=>{let max =0;for(let index =0; index < arr.length; index++){if(max < arr[index]&& max != arr[index]){
max = arr[index];}}return max;}//if you find this answer is useful ,//upvote ⇑⇑ , so can the others benefit also . @mohammad alshraideh ( ͡~ ͜ʖ ͡°)
---without sort method---publicstatic int maxValue(int[] n){
int max =Integer.MIN_VALUE;for(int each: n)if(each > max)
max = each;return max;---with sort method---publicstatic int maxValue(int[] n){Arrays.sort( n );return n [ n.lenth-1];}