Utilisation Misc.data
This commit is contained in:
@ -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) {
|
||||
|
Reference in New Issue
Block a user