第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何在頁(yè)面上獲取后對(duì)數(shù)組中的項(xiàng)目進(jìn)行排序和獲?。―iscord V12)

如何在頁(yè)面上獲取后對(duì)數(shù)組中的項(xiàng)目進(jìn)行排序和獲?。―iscord V12)

動(dòng)漫人物 2023-05-18 10:36:27
我試圖獲得 covid 案例最多的前 5 個(gè)國(guó)家/地區(qū),但是當(dāng)我嘗試為此調(diào)整另一個(gè)代碼時(shí),出現(xiàn)錯(cuò)誤。 fetch("https://pomber.github.io/covid19/timeseries.json") .then(response => response.json()) .then(data => {var countryArr = Object.keys(data).map(i => i);                countryArr.forEach((country) => {                let countryData = data[country];                countryData = countryData[countryData.length - 1];                })                                let countries = getCovidRank(countryArr, message)                countries.map((countryData, index) => {                    countries[index] = `\\?? #${index+1} | **Country**: \`\`${countryData[0]}\`\` | **Confirmed**: \`\`${countryData[0].confirmed}\`\``                    })//The rest of the code will always work, the problem is up there}這是 getCovidRank 文件:getCovidRank: (countryArr, message) => {        let countryList = []        for(var country in countryArr) {           let countryData = countryArr.confirmed            countryList.push([countryArr, (countryData[country])])        }                countryList.sort((countryData1, countryData2) => {            return countryData2[1] - countryData1[1] || countryData2[2] - countryData1[2]        })        return countryList;            }我真的希望你能幫助我,我正在努力學(xué)習(xí)如何做到這一點(diǎn)。下面的代碼顯示了全局情況(這段代碼很好):            var worldStats = { confirmed: 0, recovered: 0, deaths: 0 };            var countryArr = Object.keys(data).map(i => i);            countryArr.forEach((country) => {            let countryData = data[country];            // pick last object for today data                countryData = countryData[countryData.length - 1];                worldStats.confirmed += countryData.confirmed;                worldStats.recovered += countryData.recovered;                worldStats.deaths += countryData.deaths;            });
查看完整描述

1 回答

?
PIPIONE

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超9個(gè)贊

這是一個(gè)非常簡(jiǎn)單的演示,按確認(rèn)狀態(tài)顯示前 5 個(gè)國(guó)家。

編輯剛剛添加了一個(gè)工作片段

function init() {

  fetch("https://pomber.github.io/covid19/timeseries.json")

    .then(response => response.json())

    .then(data => {

      var countries = [];

      Object.keys(data).forEach(country => {

        var total = data[country].reduce(

          (acc, val) => (acc += val.confirmed),

          0

        );

        countries.push({

          name: country,

          confirmed: total

        });

      });

      countries.sort((a, b) => a.confirmed > b.confirmed ? -1 : 1);

      document.getElementById('div').innerHTML = countries.slice(0, 5).map(c => c.name + ' ' + c.confirmed).join('<br>');

    })

}


init();

<div id="div"></div>


查看完整回答
反對(duì) 回復(fù) 2023-05-18
  • 1 回答
  • 0 關(guān)注
  • 145 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)