Campaign/Level 9 of 12
mediumSorting1 bug

Insertion Sort Drops a Card

After sorting, one value is duplicated and another is missing.

insertionSort(arr) sorts the array ascending in place and returns it.

Fix the code so every test passes. Keep the function name insertionSort.

Test cases

  • insertionSort([5,3,4,1,2]) → [1,2,3,4,5]
  • insertionSort([2,1]) → [1,2]
  • insertionSort([1,2,3]) → [1,2,3]
  • insertionSort([3,-1,3,0]) → [-1,0,3,3]

Hints

each hint costs XP

Stuck? Hints go from a nudge to the exact fix.