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.
- Iterate through the array from the first element (
index 0) up to the second-to-last element (index length - 2). - Inside the loop, compare the current element with the one immediately after it.
- If the current element is greater than the next one, the order is broken! Print false and exit.
- If the loop finishes without finding any errors, print true.
01EXAMPLE 1
Input
[1, 2, 2, 3]Output
trueExplanation: Sorted.
Constraints
- Linear scan (O(n)).
ArraysLogic
JavaScriptSystem handles I/O — write your function only
Loading...
3 Hidden
Input Arguments
nums[1,2,2,3]
Expected Output
true
Click RUN to test your solution