Création de tableaux d'entiers

ajout d'une méthode propre pour construire un tableau d'entiers
consécutifs
This commit is contained in:
Vincent Vandemeulebrouck 2023-03-08 02:00:38 +01:00
parent 5fd3a43b2a
commit 42ed5da2d4
4 changed files with 18 additions and 14 deletions

View File

@ -119,6 +119,17 @@ export class Misc {
} }
} }
/**
* @returns an array of incremental integers (including from / excluding to).
* if max<min, the array is decrementing integers
*/
static intArray(from, to) {
if (from > to) {
return Array.from(Array(from - to).keys()).map(i => from - i)
}
return Array.from(Array(to - from).keys()).map(i => from + i)
}
static distinct(array) { static distinct(array) {
return [...new Set(array)]; return [...new Set(array)];
} }

View File

@ -190,12 +190,8 @@ export class RdDCalendrier extends Application {
/* -------------------------------------------- */ /* -------------------------------------------- */
getJoursSuivants(count) { getJoursSuivants(count) {
let jours = []; return Misc.intArray(this.timestamp.indexDate, this.timestamp.indexDate + count)
let indexDate = this.timestamp.indexDate; .map(i => { return { label: RdDTimestamp.formatIndexDate(i), index: i } })
for (let i = 0; i < count; i++, indexDate++) {
jours[i] = { label: RdDTimestamp.formatIndexDate(indexDate), index: indexDate };
}
return jours;
} }
/* -------------------------------------------- */ /* -------------------------------------------- */

View File

@ -283,12 +283,9 @@ export class RdDResolutionTable {
carac: carac, carac: carac,
difficulte: level, difficulte: level,
min: minLevel, min: minLevel,
rows: RdDResolutionTable.incrementalArray(minCarac, maxCarac), rows: Misc.intArray(minCarac, maxCarac+1),
cols: RdDResolutionTable.incrementalArray(minLevel, maxLevel) cols: Misc.intArray(minLevel, maxLevel+1)
}); });
} }
static incrementalArray(min, max) {
return Array.from(Array(max-min+1).keys()).map(i=>i+min)
}
} }

View File

@ -19,9 +19,9 @@ import { RdDRaretes } from "./item/raretes.js";
/* -------------------------------------------- */ /* -------------------------------------------- */
// This table starts at 0 -> niveau -10 // This table starts at 0 -> niveau -10
const carac_array = ["taille", "apparence", "constitution", "force", "agilite", "dexterite", "vue", "ouie", "odoratgout", "volonte", "intellect", "empathie", "reve", "chance", "melee", "tir", "lancer", "derobee"]; const carac_array = ["taille", "apparence", "constitution", "force", "agilite", "dexterite", "vue", "ouie", "odoratgout", "volonte", "intellect", "empathie", "reve", "chance", "melee", "tir", "lancer", "derobee"];
const difficultesLibres = [0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10]; const difficultesLibres = Misc.intArray(0, -11);
const ajustementsConditions = [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, +1, +2, +3, +4, +5, +6, +7, +8, +9, +10]; const ajustementsConditions = Misc.intArray(-10, 11);
const ajustementsEncaissement = [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, +1, +2, +3, +4, +5, +6, +7, +8, +9, +10, +11, +12, +13, +14, +15, +16, +17, +18, +19, +20, +21, +22, +23, +24, +25]; const ajustementsEncaissement = Misc.intArray(-10, 26);
/* -------------------------------------------- */ /* -------------------------------------------- */
function _buildAllSegmentsFatigue(max) { function _buildAllSegmentsFatigue(max) {