Compare commits

..

2 commits

Author SHA1 Message Date
d3d921b3c8 v2.1.2
All checks were successful
continuous-integration/drone/push Build is passing
2023-05-29 16:52:13 +01:00
e766a42235 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.
2023-05-29 16:48:01 +01:00
3 changed files with 7 additions and 6 deletions

7
.gitignore vendored
View file

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

View file

@ -1,6 +1,6 @@
{
"name": "random-bunny",
"version": "2.1.1",
"version": "2.1.2",
"description": "Get a random subreddit image url",
"license": "MIT",
"author": "Vylpes",

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];