Fix getRandomElement function

Now return an array item instead of an index
This commit is contained in:
2021-11-28 23:06:22 +01:00
parent 595a93087c
commit 7169faa3aa
3 changed files with 4 additions and 3 deletions

View File

@@ -97,7 +97,8 @@ export const clamp = (num: number, a: number, b: number) => {
* Return a random element from an array
*/
export const getRandomElement = (array: any[]): any => {
return ~~(array.length * Math.random())
const randomItemIndex = ~~(array.length * Math.random())
return array[randomItemIndex]
}