Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down