Order Audit

EasyAcc. 98.1%
+15 XP 5

The Order Audit

In many data systems, we assume our data is arriving in "Sorted Order" (Smallest to Largest). But as a professional developer, you must never trust your input! You need to build a scanner that verifies if every element in an array is in non-decreasing order.

The Assignment

Your mission is to verify the sorting integrity. Your function receives an array nums.

  1. Iterate through the array from the first element (index 0) up to the second-to-last element (index length - 2).
  2. Inside the loop, compare the current element with the one immediately after it.
  3. If the current element is greater than the next one, the order is broken! Print false and exit.
  4. If the loop finishes without finding any errors, print true.

01EXAMPLE 1

Input[1, 2, 2, 3]
Outputtrue

Explanation: Sorted.

Constraints

  • Linear scan (O(n)).
ArraysLogic
JavaScript
Loading...
3 Hidden

Input Arguments

nums[1,2,2,3]

Expected Output

true

Click RUN to test your solution