Sunday , September 8 2024

Examine the following code: x = [40, 10, 30, 20, 50]; x.sort(cmp); How should the function cmp be declared if, after the code execution, the elements of the array x are sorted in ascending order?

Questions BankCategory: JavaScript Essentials 1Examine the following code: x = [40, 10, 30, 20, 50]; x.sort(cmp); How should the function cmp be declared if, after the code execution, the elements of the array x are sorted in ascending order?
Examine the following code:

x = [40, 10, 30, 20, 50];
x.sort(cmp);

How should the function cmp be declared if, after the code execution, the elements of the array x are sorted in ascending order?

  • let cmp = (a, b) => b - a;
  • let cmp = (a, b) => b < a;
  • let cmp = (a, b) => b > a;
  • let cmp = (a, b) => a - b;

More Questions: JavaScript Essentials 1 – JSE1: Final Test