Skip to content

Commit 382d354

Browse files
committed
bubble sort complete
1 parent 901b3c1 commit 382d354

File tree

2 files changed

+45
-9
lines changed

2 files changed

+45
-9
lines changed

.idea/workspace.xml

Lines changed: 18 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bubbleSort.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
let bubbleSort = (myArray, cb) => {
2+
3+
let iterativeRange = myArray.length - 1;
4+
5+
while (iterativeRange --) {
6+
for (let index=0; index<myArray.length - 1; index++) {
7+
let firstValue = myArray[index];
8+
let secondValue = myArray[index + 1];
9+
10+
if (firstValue > secondValue) {
11+
myArray[index] = secondValue;
12+
myArray[index + 1] = firstValue;
13+
}
14+
}
15+
}
16+
17+
return cb(null, myArray);
18+
};
19+
20+
bubbleSort([5, 3, 8, 2, 1, 4], (err, myArray) => {
21+
if (err) {
22+
23+
} else {
24+
console.log(myArray);
25+
}
26+
});
27+

0 commit comments

Comments
 (0)