Javascript 按国家数量对大陆进行排序

Javascript 按国家数量对大陆进行排序,javascript,json,couchdb,Javascript,Json,Couchdb,我有一份国家名单: "country": [ { "countryCode": "AD", "countryName": "Andorra", "currencyCode": "EUR", "population": "84000", "capital": "Andorra la Vella", "continentName": "Europe",

我有一份国家名单:

"country": [
       {
           "countryCode": "AD",
           "countryName": "Andorra",
           "currencyCode": "EUR",
           "population": "84000",
           "capital": "Andorra la Vella",
           "continentName": "Europe",
           "continent": "EU",
           "areaInSqKm": "468.0",
           "languages": [
               "ca"
           ]
       },
       {
           "countryCode": "AE",
           "countryName": "United Arab Emirates",
           "currencyCode": "AED",
           "population": "4975593",
           "capital": "Abu Dhabi",
           "continentName": "Asia",
           "continent": "AS",
           "areaInSqKm": "82880.0",
           "languages": [
               "ar-AE",
               "fa",
               "en",
               "hi",
               "ur"
           ]
       },
etc.
现在我必须用JSON编写一个Map/Reduce函数,以获得如下输出:

关键词:南非语价值:xxx 关键词:亚洲价值:xxx 等等

其中“价值”表示各大洲的国家数量

我已经尝试过此映射功能:

function(doc) {
   var a
   {
      for (a in doc.country){
         emit(doc.country[a].continentName, 1)
      };
   }
}

映射功能:

function(doc) {
    var country = doc.country;
    var i;
        for (i in country) {
            emit (country[i].continentName, 1)
        };
}
然后您必须使用reduce函数来减少它:

function(keys, values) {
   return sum(values);}

映射功能:

function(doc) {
    var country = doc.country;
    var i;
        for (i in country) {
            emit (country[i].continentName, 1)
        };
}
然后您必须使用reduce函数来减少它:

function(keys, values) {
   return sum(values);}

我建议发出值
null
而不是
1
,并使用内置的reduce函数
\u count

我建议发出值
null
而不是
1
,并使用内置的reduce函数
\u count

你用哪种语言?你尝试了什么?@MJM:在订购json对象时要小心。根据文档和这个,它们是无序的。@AlexanderPuchkov:我使用的是JSON。我刚刚添加了我的当前函数。JSON是一种对象表示法。JSON几乎是以纯文本表示的数据。您使用的是哪种编程语言?@EpicPandaForce Javascript在Apache CouchDB中。您使用哪种语言?你尝试了什么?@MJM:在订购json对象时要小心。根据文档和这个,它们是无序的。@AlexanderPuchkov:我使用的是JSON。我刚刚添加了我的当前函数。JSON是一种对象表示法。JSON几乎是以纯文本表示的数据。您使用的是哪种编程语言?@EpicPandaForce Javascript在Apache CouchDB中。您使用哪种语言?你尝试了什么?@MJM:在订购json对象时要小心。根据文档和这个,它们是无序的。@AlexanderPuchkov:我使用的是JSON。我刚刚添加了我的当前函数。JSON是一种对象表示法。JSON几乎是以纯文本表示的数据。您使用的是什么编程语言?@EpicPandaForce Javascript在Apache CouchDB中。