alorenz keep in mind that wouldn't learn anything by copy/pasting. Give yourself time and start by solving the problem on a sheet of paper.
export const maxElement = (arr) => {
// not necessary, but useful to check for the corner case
// you'll learn more about it in the future lectures
if (!arr || !arr.length) {
throw new Error('Array is missing or empty');
}
// assume the first array element is the max
let max = arr[0];
// iterate over the array starting from the second element
for (let i = 1; i < arr.length; i++) {
// pick the current array element as max if it's greater than the current max
if (arr[i] > max) {
max = arr[i];
}
}
return max;
}