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:
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) {
return [...new Set(array)];
}