mirror of
https://github.com/Yet-Another-DreamTeam/js_algorithms.git
synced 2026-03-13 00:07:24 +00:00
first commit
This commit is contained in:
commit
6266a05dd1
18
bubblesort.js
Normal file
18
bubblesort.js
Normal file
@ -0,0 +1,18 @@
|
||||
function bubblesort(array) {
|
||||
let swap;
|
||||
let sorted;
|
||||
do {
|
||||
sorted = true;
|
||||
for (let i = 0; i < array.length; i++) {
|
||||
if (array[i] > array[i + 1]) {
|
||||
swap = array[i];
|
||||
array[i] = array[i + 1];
|
||||
array[i + 1] = swap;
|
||||
sorted = false;
|
||||
}
|
||||
}
|
||||
} while (!sorted);
|
||||
return array;
|
||||
}
|
||||
|
||||
module.exports = bubblesort;
|
||||
Loading…
x
Reference in New Issue
Block a user