Skip to content

Commit 3c5d697

Browse files
committed
Adding country name filtering on cli command
1 parent ace2150 commit 3c5d697

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lib/corona.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ function getDataByCountry(confirmed, deaths, recovered) {
2828
const confirmedMap = _.keyBy(confirmed.locations, (i) => i.country + i.province);
2929
const recoveredMap = _.keyBy(recovered.locations, (i) => i.country + i.province);
3030
const deathsMap = _.keyBy(deaths.locations, (i) => i.country + i.province);
31+
const countryName = process.argv[2].toLowerCase();
32+
3133
confirmed.locations.forEach(obj => {
3234
const countryName = obj.country;
3335
const provinceName = obj.province;
@@ -64,7 +66,9 @@ function getDataByCountry(confirmed, deaths, recovered) {
6466
const countryArr = extraStats(
6567
Object.keys(countryMap).map(key => countryMap[key])
6668
);
67-
return _.sortBy(countryArr, (o) => -o.confirmed)
69+
const countryData = (countryName) ? countryArr.filter(obj => obj.country.toLowerCase() === countryName) : _.sortBy(countryArr, (o) => -o.confirmed);
70+
71+
return countryData;
6872
}
6973

7074
function extraStats(dataArr) {

0 commit comments

Comments
 (0)