diff --git a/main.js b/main.js index e575f10..6135cb6 100644 --- a/main.js +++ b/main.js @@ -425,7 +425,7 @@ async function get_problems() { available_problems = shuffle(available_problems); - if (available_problems.length < problems_cnt) { + if (available_problems.length === 0) { Swal.fire({ icon: "error", title: "Oops...", @@ -434,8 +434,17 @@ async function get_problems() { return false; } - - let final_problems = available_problems.slice(0, problems_cnt); + let final_problems = available_problems.slice( + 0, + Math.min(problems_cnt, available_problems.length) + ); + if (available_problems.length < problems_cnt) { + Swal.fire({ + icon: "warning", + title: "Limited Results", + text: `Only ${available_problems.length} problems are available, but you requested ${problems_cnt} problems. Please adjust your filters or check back later.`, + }); + } return final_problems; }