first commit

This commit is contained in:
lucaspalomodevelop 2022-03-03 19:13:52 +01:00
commit 6266a05dd1
2 changed files with 21 additions and 0 deletions

18
bubblesort.js Normal file
View 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;

3
index.js Normal file
View File

@ -0,0 +1,3 @@
let bubblesort = require("./bubblesort");
console.log(bubblesort([1, 3, 2]));