From 1992d52a7e11df20eda2a36879c2414ba0f3a864 Mon Sep 17 00:00:00 2001 From: Saad Hasib Date: Mon, 25 Aug 2025 18:12:57 +0500 Subject: [PATCH] fix: loop ending limit --- sorts/bubble_sort.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sorts/bubble_sort.ts b/sorts/bubble_sort.ts index 5ab1f853..74217c9a 100644 --- a/sorts/bubble_sort.ts +++ b/sorts/bubble_sort.ts @@ -19,7 +19,7 @@ export const bubbleSort = (arr: number[]): number[] => { for (let i = 0; i < arr.length; i++) { - for (let j = 0; j < arr.length - 1; j++) { + for (let j = 0; j < arr.length - i; j++) { //iterating till the 2nd last element of array if (arr[j] > arr[j + 1]) { //current indexed number > next indexed number