From 0b6004b0ae6a781796fadcb877757d65c52c4511 Mon Sep 17 00:00:00 2001 From: koushitha-30734 <2400030734@kluniversity.in> Date: Tue, 25 Nov 2025 09:03:07 +0530 Subject: [PATCH] Create BubbleSortAlgo-JS I have added a simple Bubble Sort implementation in JavaScript. The code is clean, easy to understand, and follows the style of the repository. Please review and merge this PR. --- BubbleSortAlgo-JS | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 BubbleSortAlgo-JS diff --git a/BubbleSortAlgo-JS b/BubbleSortAlgo-JS new file mode 100644 index 0000000000..fce3bbc26b --- /dev/null +++ b/BubbleSortAlgo-JS @@ -0,0 +1,14 @@ +function bubbleSort(arr) { + let n = arr.length; + for (let i = 0; i < n - 1; i++) { + for (let j = 0; j < n - i - 1; j++) { + if (arr[j] > arr[j + 1]) { + // swap + [arr[j], arr[j + 1]] = [arr[j + 1], arr[j]]; + } + } + } + return arr; +} + +console.log(bubbleSort([5, 3, 8, 1, 2])); // Output: [1, 2, 3, 5, 8]