Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
  • Loading branch information
koushitha-30734 authored Nov 25, 2025
commit 0b6004b0ae6a781796fadcb877757d65c52c4511
14 changes: 14 additions & 0 deletions BubbleSortAlgo-JS
Original file line number Diff line number Diff line change
@@ -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]