get largest number in array javascript
const array1 = [1, 3, 2];
Math.max(...array1);
// expected output: 3
get largest number in array javascript
const array1 = [1, 3, 2];
Math.max(...array1);
// expected output: 3
Return Largest Numbers in Arrays
// Return Largest Numbers in Arrays
function largestOfFour(arr) {
let largestArr = [];
for (let i = 0; i < arr.length; i++) {
largestArr.push(Math.max(...arr[i]));
}
return largestArr;
}
largestOfFour([
[4, 5, 1, 3],
[13, 27, 18, 26],
[32, 35, 37, 39],
[1000, 1001, 857, 1],
]);
// OR
function largestOfFour(arr) {
return arr.map(function (group) {
return group.reduce(function (prev, current) {
return current > prev ? current : prev;
});
});
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us