Q:

Write a JavaScript program to get the largest even number from an array of integers

0

Write a JavaScript program to get the largest even number from an array of integers

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

function max_even(arra) {

  arra.sort((x, y) => y - x);

  for (var i = 0; i < arra.length; i++) {
    if (arra[i] % 2 == 0)
      return arra[i];
    }
  }

console.log(max_even([20, 40, 200]));
console.log(max_even([20, 40, 200, 301]));

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now