๐Ÿš€ Everything is free โ€” help us improve! Submit feedback and shape the platform.
๐Ÿ›Debugging Missionยทintermediateยทโฑ๏ธ 20โ€“30mยทโญ 150 XP

M-065Fix the Broken Sort

Description

The array sorting function at Nebula Corp is producing wrong results for certain inputs. Engineers have reported that numeric arrays come back in the wrong order. Dig into the code, find the bug, and fix it.

Symptoms

wrong-outputNumbers are sorted lexicographically instead of numerically
wrong-outputsortArray([10, 2, 1]) returns [1, 10, 2] instead of [1, 2, 10]

Expected Behavior (2)

Sorts positive integers
Basic numeric sort
Input:sortArray([10, 2, 1])
Expected:CONTAINS:1,2,10
Sorts negative numbers
Handles negatives
Input:sortArray([-3, 1, -1])
Expected:CONTAINS:-3,-1,1

Related Lessons

Click Run / Check to validate your solution