diff --git a/frontend/src/lib/index.ts b/frontend/src/lib/index.ts index 042c1cf..4c78c57 100644 --- a/frontend/src/lib/index.ts +++ b/frontend/src/lib/index.ts @@ -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'; diff --git a/frontend/src/lib/randomItemInArray.ts b/frontend/src/lib/randomItemInArray.ts new file mode 100644 index 0000000..719f31c --- /dev/null +++ b/frontend/src/lib/randomItemInArray.ts @@ -0,0 +1,4 @@ +export function randomItemInArray(arr: Array): T { + const index = Math.floor(Math.random() * arr.length); + return arr[index]; +}