From 2dd002eb7eb96090ed084aa6a1fc8b1ac22dcbc7 Mon Sep 17 00:00:00 2001 From: YoussifHassan8 Date: Thu, 8 Aug 2024 19:18:39 +0300 Subject: [PATCH 1/2] Getting minimum number of problems --- main.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/main.js b/main.js index e575f10..de24476 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,14 @@ async function get_problems() { return false; } - let final_problems = available_problems.slice(0, problems_cnt); + 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; } From c460914cb908913d9bf9a4316dc5ccec83fca27d Mon Sep 17 00:00:00 2001 From: YoussifHassan8 Date: Fri, 9 Aug 2024 17:28:58 +0300 Subject: [PATCH 2/2] Implemented requested changes for PR --- main.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/main.js b/main.js index de24476..6135cb6 100644 --- a/main.js +++ b/main.js @@ -434,7 +434,10 @@ 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",