aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils.ts
diff options
context:
space:
mode:
authorMaksymilian Jopek <maks@jopek.eu>2022-04-21 13:44:38 +0200
committerMaksymilian Jopek <maks@jopek.eu>2022-04-21 15:55:51 +0200
commitca7f97e765024b3ba279f2c4485e28add7b7e1a7 (patch)
treef696510846b2654151ba99aebafcf5bb5445e254 /src/utils.ts
parent6b08c641e9ad1f3b1c7ecc626efc0ee34d3d6925 (diff)
downloadboules-ca7f97e765024b3ba279f2c4485e28add7b7e1a7.tar.gz
boules-ca7f97e765024b3ba279f2c4485e28add7b7e1a7.tar.zst
boules-ca7f97e765024b3ba279f2c4485e28add7b7e1a7.zip
v1.0.0
Diffstat (limited to 'src/utils.ts')
-rw-r--r--src/utils.ts14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/utils.ts b/src/utils.ts
index a767896..48771e9 100644
--- a/src/utils.ts
+++ b/src/utils.ts
@@ -1,12 +1,26 @@
/**
* Returns a random number between min (inclusive) and max (exclusive)
+ * @param min - minimum
+ * @param max - maximum
+ * @returns Random int
*/
export function getRandomInt(min: number, max: number): number {
return Math.floor(Math.random() * (max - min) + min);
}
+/**
+ * Gets random element from array
+ * @typeParam T - type of elements inside given array
+ * @param arr - array
+ * @returns Random element from given array
+*/
export function getRandomEl<T>(arr: Array<T>): T {
return arr[getRandomInt(0, arr.length)];
}
+/**
+ * Function that sleeps
+ * @param time - sleep for this time [ms]
+ * @returns Promise that resolves after `time`s
+*/
export async function sleep(time: number) {
return new Promise(resolve => setTimeout(resolve, time));
}