Skip to content
This repository has been archived by the owner on Oct 22, 2021. It is now read-only.

implemented bubble sort using javascript #90

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
16 changes: 16 additions & 0 deletions Sorting Algorithms/Bubble Sort/BubbleSort.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Javascript program for implementation of Bubble Sort
const bubbleSort = (arr) => {
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < arr.length - i - 1; j++) {
if (arr[j + 1] < arr[j]) {
// swapping the elements
[arr[j + 1], arr[j]] = [arr[j], arr[j + 1]];
}
}
}
return(arr);
}

// driver program
const sortedArray = bubbleSort([5,10,1,3,2,7,8,9,6,4]);
console.log(sortedArray);