@kuzanatoliorg/algorithms
Version:
The utils package for react testing library
21 lines (20 loc) • 641 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.bubbleSort = void 0;
const utils_1 = require("../utils");
const bubbleSort = (arr, comparator = utils_1.defaultComparator, order = true) => {
let i, j, item;
for (i = 0; i < arr.length; i++) {
for (j = 1; j < arr.length - i; j++) {
if (order
? comparator(arr[j], arr[j - 1])
: comparator(arr[j - 1], arr[j])) {
item = arr[j];
arr[j] = arr[j - 1];
arr[j - 1] = item;
}
}
}
return arr;
};
exports.bubbleSort = bubbleSort;