From 8b45a6270db7359cc3016835e277c0cd294b7c96 Mon Sep 17 00:00:00 2001 From: Roman Date: Sun, 13 Oct 2024 21:42:55 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D1=82=20?= =?UTF-8?q?=D0=B2=D1=81=D0=BF=D0=BE=D0=BC=D0=BE=D0=B3=D0=B0=D1=82=D0=B5?= =?UTF-8?q?=D0=BB=D1=8C=D0=BD=D1=8B=D0=B5=20=D1=84=D1=83=D0=BD=D0=BA=D1=86?= =?UTF-8?q?=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/shared/helpers/functions.ts | 13 +++++++++++++ src/shared/helpers/index.ts | 1 + 2 files changed, 14 insertions(+) create mode 100644 src/shared/helpers/functions.ts create mode 100644 src/shared/helpers/index.ts diff --git a/src/shared/helpers/functions.ts b/src/shared/helpers/functions.ts new file mode 100644 index 0000000..c971d91 --- /dev/null +++ b/src/shared/helpers/functions.ts @@ -0,0 +1,13 @@ +export function getRandomNumber(min: number, max: number, numAfterDigit: number = 0) { + return +((Math.random() * (max - min)) + min).toFixed(numAfterDigit); +} + +export function getRandomItems(items: T[]):T[] { + const startPosition = getRandomNumber(0, items.length - 1); + const endPosition = startPosition + getRandomNumber(startPosition, items.length); + return items.slice(startPosition, endPosition); +} + +export function getRandomElement(items: T[]):T { + return items[getRandomNumber(0, items.length - 1)]; +} diff --git a/src/shared/helpers/index.ts b/src/shared/helpers/index.ts new file mode 100644 index 0000000..d67b765 --- /dev/null +++ b/src/shared/helpers/index.ts @@ -0,0 +1 @@ +export {getRandomElement, getRandomNumber, getRandomItems} from './functions.js';