Skip to content

Commit

Permalink
Fix bug where the randomiser would pick -1
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Vylpes committed May 29, 2023
1 parent e7620cc commit e766a42
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
dist
yarn-error.log
node_modules/
dist/
coverage/
yarn-error.log
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit e766a42

Please sign in to comment.