merge-sort-nat
Version:
Merge sort library made for testing class
39 lines (38 loc) • 1.62 kB
JavaScript
;
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getRandomString = exports.getRandomInt = exports.shuffleArray = exports.shuffledArrays = void 0;
function getRandomInt(min, max) {
return min + Math.floor(Math.random() * (max - min + 1));
}
exports.getRandomInt = getRandomInt;
function getRandomString(size) {
var asciiCodes = new Array(size).fill(0).map(function () { return getRandomInt(31, 128); });
return String.fromCharCode.apply(String, asciiCodes);
}
exports.getRandomString = getRandomString;
function shuffleArray(array) {
var _a;
var copyArray = __spreadArray([], array, true);
for (var i = copyArray.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
_a = [copyArray[j], copyArray[i]], copyArray[i] = _a[0], copyArray[j] = _a[1];
}
return copyArray;
}
exports.shuffleArray = shuffleArray;
function shuffledArrays(size, filler, mapper, minArraySize, maxArraySize) {
return new Array(size).fill(filler).map(function () {
var oArray = new Array(getRandomInt(minArraySize, maxArraySize)).fill(filler).map(mapper);
return [shuffleArray(oArray), oArray];
});
}
exports.shuffledArrays = shuffledArrays;