Interactive online courses HTML Academy
2026-03-09 14:13 Diff

Fix the sorting function so that the states of the array during sorting match the sample.

To view the sample or test your program, click the button Boss, here’s your program!

Solution

The solution to the challenge will be available in a few minutes. Use it if you encounter difficulties. In the meantime, try to complete the challenge on your own.

let arr = [1, 3, 5, 4, 1]; draw(arr); bubbleSort(arr); function bubbleSort(arr) { let len = arr.length - 1; for (let pass = 0; pass < len; pass++) { for (let j = 0; j < len - pass; j++) { if (arr[j] > arr[j + 1]) { let temp = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = temp; draw(arr, j, j + 1); } } } }