Instructions

  • 1. Your final score will reflect your grasp of the concepts—approach each question with precision.
  • 2. Thoroughly review each solution before proceeding to ensure full understanding.
  • 3. Final results will be available after submission to provide insights into areas for further improvement.
  • 4. Maintain academic integrity—plagiarism undermines learning and professional growth.
  • 5. Once submitted, responses are final, so ensure you’re confident in your answers.
  • 6. These challenges are designed to test practical knowledge; apply your skills as you would in real-world scenarios.

All Problems

Question

Action

What is the default behavior of the sort() method?

View

How do you sort an array of numbers in ascending order?

View

What does the reverse() method do?

View

Which of the following arrays is sorted by sort() in JavaScript by default?

View

How can you sort an array of strings in descending order?

View

What is the result of the following code?

View

How do you reverse an array?

View

Which method is used to sort an array in place?

View

What does the following code return?

View

What is the output of this code?

View

What is the default behavior of the sort() method?

Sorts values as strings in ascending order
Sorts values as numbers in ascending order
Sorts values in descending order
Does nothing unless a compare function is provided

How do you sort an array of numbers in ascending order?

arr.sort()
arr.sort((a, b) => a - b)
arr.sort((a, b) => b - a)
arr.sort(() => 0)

What does the reverse() method do?

Reverses the order of the array elements
Sorts the array in descending order
Removes the last element of the array.
Duplicates the array

Which of the following arrays is sorted by sort() in JavaScript by default?

['banana', 'apple', 'cherry']
[1, 5, 10, 15]
[10, 5, 1, 15]
['2', '10', '3']

How can you sort an array of strings in descending order?

arr.sort().reverse()
arr.sort((a, b) => b - a)
arr.sort((a, b) => a - b).reverse()
arr.reverse()

What is the result of the following code?

const arr = [10, 5, 1, 15]; arr.sort((a, b) => a - b); console.log(arr);

[1, 5, 10, 15]
[15, 10, 5, 1]
[10, 5, 1, 15]
[5, 1, 15, 10]

How do you reverse an array?

arr.reverse()
arr.sort(() => -1)
arr.sort().reverse()
arr.splice()

Which method is used to sort an array in place?

sort()
reverse()
map()
filter()

What does the following code return?

const arr = ['banana', 'apple', 'cherry']; arr.sort(); console.log(arr);

['apple', 'banana', 'cherry']
['banana', 'cherry', 'apple']
['cherry', 'apple', 'banana']
['apple', 'cherry', 'banana']

What is the output of this code?

const arr = [2, 5, 10, 1]; arr.sort(); arr.reverse(); console.log(arr);

[10, 5, 2, 1]
[1, 2, 5, 10]
[2, 5, 1, 10]
[10, 1, 5, 2]