Skip to content

Commit 1992d52

Browse files
author
Saad Hasib
committed
fix: loop ending limit
1 parent 19b4ced commit 1992d52

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

sorts/bubble_sort.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
export const bubbleSort = (arr: number[]): number[] => {
2121
for (let i = 0; i < arr.length; i++) {
22-
for (let j = 0; j < arr.length - 1; j++) {
22+
for (let j = 0; j < arr.length - i; j++) {
2323
//iterating till the 2nd last element of array
2424
if (arr[j] > arr[j + 1]) {
2525
//current indexed number > next indexed number

0 commit comments

Comments
 (0)