Skip to content

Commit e586a23

Browse files
authored
Update Bubble Sort.md
1 parent 17031f1 commit e586a23

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

Basic Algorithm Scripting/Bubble Sort/Bubble Sort.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ function bubbleSortWithForLoops(arr) {
4747
for (var i = 0; i < arr.length; i++) {
4848
// Notice that j < (length - i)
4949
for (var j = 0; j < arr.length - i - 1; j++) {
50-
// Compare the adjacent positions
51-
if (arr[j] > arr[j + 1]) {
52-
// Swap the numbers
53-
// Temporary variable to hold the current number
54-
var tmp = arr[j]
55-
// Replace current number with adjacent number
56-
arr[j] = arr[j + 1]
50+
// Compare the adjacent positions
51+
if (arr[j] > arr[j + 1]) {
52+
// Swap the numbers
53+
// Temporary variable to hold the current number
54+
var tmp = arr[j]
55+
// Replace current number with adjacent number
56+
arr[j] = arr[j + 1]
5757
// Replace adjacent number with current number
5858
arr[j + 1] = tmp
5959
}
@@ -70,12 +70,12 @@ function bubbbleSort(arr) {
7070
do {
7171
swapped = false
7272
arr.forEach((item, index) => {
73-
if (item > arrr[index + 1]) {
74-
let temp = item
75-
arr[index] = arr[index + 1]
76-
arr[index + 1] = temp
77-
swapped = true
78-
}
73+
if (item > arr[index + 1]) {
74+
let temp = item
75+
arr[index] = arr[index + 1]
76+
arr[index + 1] = temp
77+
swapped = true
78+
}
7979
})
8080
} while (swapped)
8181
return arr

0 commit comments

Comments
 (0)