i need some help in my code
if see the visit api url you will see Large Data duplicated
const url = 'https://raw.githubusercontent.com/globaldothealth/monkeypox/main/latest.json';
async function getData() {
const response = await fetch(url);
const data = await response.json();
console.log(data);
How we Can Merge all data and Sum it like to show have 500 infected named Confirmed And SUSPACKTED AND SHOW IT BY Numbar
You simply need an object to store and count the cases while iterating over the array of persons. Find an implementation below:
const url =
"https://raw.githubusercontent.com/globaldothealth/monkeypox/main/latest.json";
async function getData() {
const response = await fetch(url);
const data = await response.json();
return data;
}
function getResults(data) {
const results = {
confirmed: 0,
suspected: 0,
};
data.forEach((person) => {
switch (person.Status) {
case "confirmed":
results.confirmed ++;
break;
case "suspected":
results.suspected ++;
break;
default:
break;
}
});
return results;
}
(async function () {
const data = await getData();
const results = getResults(data);
console.log(
`${results.confirmed} confirmed cases\n${results.suspected} suspected cases.`
);
})();