Skip to content

Commit 60b984c

Browse files
committed
feat: add bubble sort
1 parent 9ebce60 commit 60b984c

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

bubble_srt/index.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const bubbleSort = (data) => {
2+
const arr = [...data];
3+
4+
for (let i = 0; i < arr.length; i++) {
5+
for (let j = 0; j < arr.length - i - 1; j++) {
6+
if (arr[j] > arr[j + 1]) {
7+
const tmp = arr[j];
8+
arr[j] = arr[j + 1];
9+
arr[j + 1] = tmp;
10+
}
11+
}
12+
}
13+
14+
return arr;
15+
}
16+
17+
const data = [1, 5, 2, 11, 5, 7];
18+
19+
console.log(bubbleSort(data));

bubble_srt/package.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "bubble_srt",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "ISC"
12+
}

0 commit comments

Comments
 (0)