Utilisation Misc.data

This commit is contained in:
Vincent Vandemeulebrouck
2021-03-29 18:08:18 +02:00
parent 592f54af61
commit 31204cbf51
21 changed files with 254 additions and 237 deletions

View File

@ -18,6 +18,24 @@ export class Misc {
return isPositiveNumber ? "+" + number : number
}
static sum() {
return (a, b) => a + b;
}
static ascending(orderFunction) {
return (a, b) => Misc.sortingBy(orderFunction(a), orderFunction(b));
}
static descending(orderFunction) {
return (a, b) => Misc.sortingBy(orderFunction(b), orderFunction(a));
}
static sortingBy(a, b) {
if (a > b) return 1;
if (a < b) return -1;
return 0;
}
/**
* Converts the value to an integer, or to 0 if undefined/null/not representing integer
* @param {*} value value to convert to an integer using parseInt
@ -55,7 +73,7 @@ export class Misc {
}
return itemsBy;
}
static classifyInto(itemsBy, items, classifier = it => it.type, transform = it => it) {
for (const item of items) {
const classification = classifier(item);
@ -72,7 +90,7 @@ export class Misc {
}
static rollOneOf(array) {
return array[new Roll("1d" + array.length).evaluate( { async: false} ).total - 1];
return array[new Roll("1d" + array.length).evaluate({ async: false }).total - 1];
}
static distinct(array) {