Easy there, pal!
To access the Bubble sort challenges in the Sorting Algorithms Made Visual, you need to sign up and subscribe first.
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 = [6, 3, 8, 4, 5];
draw(arr);
bubbleSort(arr);
function bubbleSort(arr) {
let len = arr.length - 1;
for (let i = 0; i < len; i++) {
for (let j = 0; j < len - i; 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);
}
}
}
}You’ve gone to a different page
Click inside the mini-browser to shift the focus onto this window.
To access the Bubble sort challenges in the Sorting Algorithms Made Visual, you need to sign up and subscribe first.
Have you forgotten your password or lost access to your profile? Enter your email connected to your profile and we will send you a link to restore access.
Forgot to connect your email to the profile? Email us and we’ll help.