feat: [frontend] Add randomItemInArray helper
This commit is contained in:
parent
e075f2dc39
commit
4c60a3ca91
2 changed files with 5 additions and 0 deletions
|
|
@ -1,2 +1,3 @@
|
|||
// place files you want to import through the `$lib` alias in this folder.
|
||||
export { shuffleArray } from './shuffleArray';
|
||||
export { randomItemInArray } from './randomItemInArray';
|
||||
|
|
|
|||
4
frontend/src/lib/randomItemInArray.ts
Normal file
4
frontend/src/lib/randomItemInArray.ts
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
export function randomItemInArray<T>(arr: Array<T>): T {
|
||||
const index = Math.floor(Math.random() * arr.length);
|
||||
return arr[index];
|
||||
}
|
||||
Loading…
Reference in a new issue