Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

max value in array javascript

// 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) => { return Math.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);
Comment

js get max value in an array

const myArray = [1, 14, 32, 7];

const maxValue = Math.max(...myArray);

console.log(maxValue); // 32
Comment

find maximum number in array

#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]);

    return 0;
}
Comment

max and min value in array

 public static void main(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);
    }
Comment

javascript min max array

Math.max(1, 2, 3)    // 3
Math.min(1, 2, 3)    // 1

var nums = [1, 2, 3]
Math.min(...nums)    // 1
Math.max(...nums)    // 3
Comment

find maximum minimum element of an array

    vector<int>arr {1, 34 , 50, 4, 400};
    int maximumElement = *max_element(arr.begin(), arr.end());
    int minimumElement = *min_element(arr.begin(), arr.end());
Comment

max value from array in javascript

// 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).
  }
}
Comment

find max and min value in array javascript

var numbers = [1, 2, 3, 4];
Math.max(...numbers) // 4
Math.min(...numbers) // 1
Comment

Max Number from Array in JS

function arrayMax(array) {
  return array.reduce(function(a, b) {
    return Math.max(a, b);
  });
}

function arrayMin(array) {
  return array.reduce(function(a, b) {
    return Math.min(a, b);
  });
}
Comment

find max value in array javascript

// find maximum value of array in javascript
// array reduce method
const arr = [49,2,71,5,38,96];
const max = arr.reduce((a, b) => Math.max(a, b));
console.log(max); // 96

// math.max apply method
const max_ = Math.max.apply(null, arr);
console.log(max_); // 96

// or math.max spread operator method
const max__ = Math.max(...arr);
console.log(max__); // 96
Comment

how to return the max and min of an array in javascript

function minMax(arr) {
  return [Math.min(...arr), Math.max(...arr)];
}
Comment

js max with array

var myArray = [5, 10, 50];
Math.max(myArray);    // Error: NaN
Math.max.apply(Math, myArray);    // 50
Comment

how to find max number in array javascript

const array1 = [1, 3, 2];
console.log(Math.max(...array1));
Comment

max element in array

int max;
max=INT_MIN;

for(int i=0;i<ar.length();i++){
	if(ar[i]>max){
    	max=ar[i];
    }

       
Comment

get min/max array

function arrayMin(arr) {
  return arr.reduce(function (p, v) {
    return ( p < v ? p : v );
  });
}

function arrayMax(arr) {
  return arr.reduce(function (p, v) {
    return ( p > v ? p : v );
  });
}
Comment

js how to find max value in an array

(function () {
  const arr = [23, 65, 3, 19, 42, 74, 56, 8, 88];

  function findMaxArrValue(arr) {
    if (arr.length) {
      let max = -Infinity;

      for (let num of arr) {
        max = num > max ? num : max;
      }
      return max;
    }
    return 0; // or any value what you need
  }

  console.log(findMaxArrValue(arr)); // => 88
})();
Comment

get max number in array

console.log(arrayNumbers.sort((a, b) => a - b ));
Comment

find the max number in an array js

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;
Comment

max value in an array

console.log(Math.max(1, 3, 2));
// expected output: 3

console.log(Math.max(-1, -3, -2));
// expected output: -1

const array1 = [1, 3, 2];

console.log(Math.max(...array1));
// expected output: 3
Comment

find minimum and maximum element in an array

#In python
#List
myListName = ["value", 3, 3.1, "a", True]
minimumValue = min(myListName)
maximumValue = max(myListName)

#Numpy array
import numpy as np
myListName = ["value", 3, 3.1, "a", True]
myArrayName = np.array(myListName)
minimumValue = min(myArrayName)
maximumValue = max(myArrayName)
Comment

max array

const findMax = (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 ( ͡~ ͜ʖ ͡°)
Comment

array max in javascript

javascript array maximum
Comment

find the maximum and minimum values of an array.

public class Main {
public static void main(String[] args){
int[] numbers = {1,2,3,4};
System.out.println("This is your min value:");
getMinimum (numbers);
System.out.println("This is your max value:");
getMaximum (numbers);
}
private static void getMinimum (int[] arr) {
int min = arr[0];
for (int i = 0; i < arr.length; i++) {
if (arr.length < min) {
min = arr[i];
}
}
System.out.println(min);
}
private static void getMaximum (int[] arr) {
int max = arr[0];
for (int i = 0; i < arr.length; i++) {
if (arr.length > max) {
max = arr[i];
}
}
System.out.println(max);
}
}
Comment

PREVIOUS NEXT
Code Example
Java :: matrice java 
Java :: java math power 
Java :: check if list includes value java 
Java :: java declare a list 
Java :: java println 
Java :: pointers in java 
Java :: find length of array java 
Java :: 123 movies 
Java :: how to use sql file in java 
Java :: setbackground java 
Java :: java running sum of array 
Java :: sorting java 
Java :: java.lang.object[4] 
Java :: hello world program in java 
Java :: is palindrome java 
Java :: java look and feel system 
Java :: make textview invisible android 
Java :: reverse a string in java 
Java :: method reference in java 
Java :: java indexof all occurrences 
Java :: arrays.copy 2d array 
Java :: get string from int java 
Java :: function overriding java 
Java :: java get object from string name 
Java :: java substring based on delimiter 
Java :: java types of list 
Java :: console java 
Java :: java Overridding example 
Java :: commenting in java 
Java :: what is whitespace in java 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =