Fix bug where the randomiser would pick -1
All checks were successful
continuous-integration/drone/push Build is passing

This was caused by the randomiser using the wrong brackets.

We needed the maximum index of the length - 1, but the randomiser would
take the 1 AFTER randomising, adding brackets made it do this BEFORE.
This commit is contained in:
Ethan Lane 2023-05-29 16:48:01 +01:00
parent e7620ccd42
commit e766a42235
2 changed files with 6 additions and 5 deletions

5
.gitignore vendored
View file

@ -1,3 +1,4 @@
node_modules
dist
node_modules/
dist/
coverage/
yarn-error.log

View file

@ -41,8 +41,8 @@ export default async function randomBunny(subreddit: string, sortBy?: string): P
return {
IsSuccess: false,
};
} else if (dataWithImages.length > 1) {
random = Math.floor((Math.random() * dataWithImages.length - 1) + 0); // Between 0 and (size - 1)
} else {
random = Math.floor((Math.random() * (dataWithImages.length - 1)) + 0); // Between 0 and (size - 1)
}
const randomSelect = dataWithImages[random];