From bb5728d105a594d40455f4d2d7f558bd641027e4 Mon Sep 17 00:00:00 2001 From: kian omoomi <59165380+kianomoomi@users.noreply.github.com> Date: Thu, 3 Feb 2022 22:06:36 +0330 Subject: [PATCH] Update index.js --- index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/index.js b/index.js index d831d02..f6916de 100644 --- a/index.js +++ b/index.js @@ -23,6 +23,11 @@ const getRandomCountry = () => { */ const getNRandomCountriesData = (count) => { let randomCountriesSet = new Set(); // to prevent duplicate countries + // if count is bigger than number of all countries, it should show all countries + if(count > data.length){ + console.log("your input is greater than number of all countries. So all countries will be shown instead...") + return data + } while (randomCountriesSet.size < count) { let country = data[randomNum()]; randomCountriesSet.add(country); // adds a country to the Array