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:
@ -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)];
|
||||
}
|
||||
|
Reference in New Issue
Block a user