add dataGenerator.js

This commit is contained in:
lucaspalomodevelop 2022-03-03 19:23:58 +01:00
parent d4617312ea
commit ab3a8ebaeb
2 changed files with 26 additions and 2 deletions

22
dataGenerator.js Normal file
View File

@ -0,0 +1,22 @@
function generateSortedIntArray(length) {
let array = [];
for (let index = 0; index < length; index++) {
array.push(index + 1);
}
return array;
}
function generateUnsortedIntArray(length) {
let array = generateSortedIntArray(length);
array.sort(function (a, b) {
return 0.5 - Math.random();
});
return array;
}
module.exports = {
generateSortedIntArray,
generateUnsortedIntArray,
};

View File

@ -1,6 +1,8 @@
let bubblesort = require("./bubblesort");
let dataGenerator = require("./dataGenerator");
console.log(bubblesort([1, 3, 2], true));
let data = dataGenerator.generateUnsortedIntArray(1000);
console.log(dataGenerator.generateUnsortedIntArray(10));
console.time("bubblesort");
console.log(bubblesort(data, true));
console.timeEnd("bubblesort");