xxxxxxxxxx
function findMaxArrValue(numbers) {
let max = 0;
numbers.forEach((number) => {if (number > max) {max = number}});
return max;
}
console.log(findMaxArrValue([23, 69, 55, 31, 75, 100, 82]));
//Output 100
xxxxxxxxxx
var arr = [3, 6, 2, 56, 32, 5, 89, 32];
var largest = arr[0];
for (var i = 0; i < arr.length; i++) {
if (largest < arr[i] ) {
largest = arr[i];
}
}
console.log(largest);
xxxxxxxxxx
var arr = [1, 2, 3];
var max = arr.reduce(function(a, b) {
return Math.max(a, b);
});
xxxxxxxxxx
function getMaxOfArray(numArray) {
return Math.max.apply(null, numArray);
}
xxxxxxxxxx
#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;
}
xxxxxxxxxx
// 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
xxxxxxxxxx
(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
})();
xxxxxxxxxx
//We define a function findMax that takes an array arr as an argument.
//Inside the function, we use the spread operator (...) to spread the elements of the array as arguments to the Math.max function.
//This effectively finds the maximum element in the array.
const findMax = arr => Math.max(arr);
// Example usage:
const numbers = [10, 5, 8, 20, 3];
const maxNumber = findMax(numbers);
console.log(maxNumber); // Output: 20
xxxxxxxxxx
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;