Skip to content

Commit

Permalink
Добавит вспомогательные функции
Browse files Browse the repository at this point in the history
  • Loading branch information
RnizereB committed Oct 13, 2024
1 parent 2aea1aa commit 8b45a62
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/shared/helpers/functions.ts
Original file line number Diff line number Diff line change
@@ -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<T>(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<T>(items: T[]):T {
return items[getRandomNumber(0, items.length - 1)];
}
1 change: 1 addition & 0 deletions src/shared/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {getRandomElement, getRandomNumber, getRandomItems} from './functions.js';

0 comments on commit 8b45a62

Please sign in to comment.