Remove MaxTries variable #51

Merged
Vylpes merged 6 commits from feature/34-remove-max-tries into develop 2023-02-24 20:31:22 +00:00
2 changed files with 25 additions and 27 deletions
Showing only changes of commit 089f693413 - Show all commits

2
app.ts
View file

@ -1,7 +1,7 @@
import randomBunny from "./dist";
async function app() {
const result = await randomBunny('rabbits', 'hot', 100);
const result = await randomBunny('rabbits', 'hot');
console.log(result);
}

View file

@ -10,7 +10,7 @@ const sortable = [
'top'
];
export default async function randomBunny(subreddit: string, sortBy?: string, maxTries = 100): Promise<IReturnResult> {
export default async function randomBunny(subreddit: string, sortBy?: string): Promise<IReturnResult> {
if (!sortBy || !sortable.includes(sortBy)) sortBy = 'hot';
const result = await fetch(`https://reddit.com/r/${subreddit}/${sortBy}.json`);
@ -35,12 +35,15 @@ export default async function randomBunny(subreddit: string, sortBy?: string, ma
.Where(x => x!.data.url.includes('.jpg') || x!.data.url.includes('.png'))
.ToArray();
for (let i = 0; i < maxTries; i++) {
const random = Math.floor((Math.random() * dataWithImages.length - 1) + 0); // Between 0 and (size - 1)
const randomSelect = dataWithImages[random];
if (!randomSelect) continue;
if (!randomSelect) {
return {
IsSuccess: false,
};
};
const randomData = randomSelect.data;
@ -61,8 +64,3 @@ export default async function randomBunny(subreddit: string, sortBy?: string, ma
Result: redditResult
};
}
return {
IsSuccess: false
}
}