Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sorting 对象的排序API调用_Sorting - Fatal编程技术网

Sorting 对象的排序API调用

Sorting 对象的排序API调用,sorting,Sorting,我试图以降序显示redditSub计数。我的功能只是在控制台中显示已排序的数据,而不是在页面上。我需要帮助。先谢谢你。git存储库的链接如下所示:- var subRedditNames=[ “比特币,BTC”,“以太坊,ETH”,“二进制,BNB”,“系链,USDT”,“点,点”,]; //在此处添加reddit名称 var collectedData=[];//未排序的数据存储在此数组中 //加载文档后,我们将获取所有子Reddit名称 $(文档).ready(函数(){ console.

我试图以降序显示redditSub计数。我的功能只是在控制台中显示已排序的数据,而不是在页面上。我需要帮助。先谢谢你。git存储库的链接如下所示:-

var subRedditNames=[
“比特币,BTC”,“以太坊,ETH”,“二进制,BNB”,“系链,USDT”,“点,点”,];
//在此处添加reddit名称
var collectedData=[];//未排序的数据存储在此数组中
//加载文档后,我们将获取所有子Reddit名称
$(文档).ready(函数(){
console.log(“已加载文档”);
//收集阵列中所有Reddit的数据。
//既然是我们
for(设i=0;i(a.redditSubs
var subRedditNames = [
"bitcoin,BTC","ethereum,ETH", "binance,BNB", "Tether,USDT", "dot,DOT",]; 
// add reddit name here

var collectedData = []; // unsorted data is stored inside this array
// Once the document is load we fetch all subreddit names
$(document).ready(function () {
console.log("Document Loaded.");
// Collects data for all reddits in the array.
// Since fetch is we
for (let i = 0; i < subRedditNames.length; i++) {
// Split the index to get the
var coinInfo = subRedditNames[i].split(",");
// The reddit name is stored before the ',' so input index '0'
Get_RedditSubCount(coinInfo[0], coinInfo[1]);
}
});

// when given a subredded ex: 'https://www.reddit.com/r/Bitcoin/' we can search for that
// subreddits information.
function Get_RedditSubCount(subRedditName, symbol) {
fetch(`https://www.reddit.com/r/${subRedditName}/about.json`)
.then(function (response) {
return response.json();
})
.then(function (data) {
// Calls another function to reduce mess inside fetch
return CollectData(symbol, subRedditName, data.data.subscribers);
})
.catch(function (error) {
console.log(error);
});
}


// This function pushes information into an array 'collectedData' and then creates a card
// for the crypto.
// TODO: Sort 'collectedData' after all the fetch functions have completed.
// fetch is async so you need to make sure all fetches have completed
function CollectData(symbol, name, subRedditSubscribers) {
// Store data for use later.

var item = 
{ coinSymbol: symbol, redditName: name, redditSubs: subRedditSubscribers };

collectedData.push(item);
collectedData.sort((a, b) => (a.redditSubs < b.redditSubs) ? 1 : -1);
console.log(collectedData);
//end of sorting function
CreateCoinCard(symbol, name, subRedditSubscribers);
}

function CreateCoinCard(symbol, name, subscribers) {
// Now that we've stored the data, add the info to the chart
var coinCardHTML = "";
coinCardHTML += `<div class="row">
<div class="col-1">1</div>
<input class="col-1 star" type="checkbox" />
<div class="col">${symbol}: r/${name}</div>
<div cass="col">${subscribers}</div>
</div>`;
$(".container").append(coinCardHTML);

}