settingsAccountsettings
By using our mini forum, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy
Menusettings

Q: Max Element (task with advanced JavaScript functions)

+2 votes

Write a JS program that takes an array of numeric elements as input and returns the largest element of the array.

Input:
You will receive an array of numbers.

Output:
The output should be the return value of your function. It represents the largest element of the array.

Examples:

Sample Input:

[10, 20, 5]

Output:

20


Sample Input:

[1, 44, 123, 33]

Output:

123

asked in JavaScript category by user ak47seo

1 Answer

0 votes

My solution:

function maxElement(arr) {
    return Math.max.apply(null, arr);
}

console.log(maxElement([10, 20, 5]));

 

answered by user andrew
...