{"size": 1069, "ext": "js", "max_stars_repo_path": "couchdb/tdrepo/design/tdr/views/newestaip.js", "max_stars_repo_name": "c7a/cihm-repomanage", "max_stars_repo_stars_event_min_datetime": "2019-09-09T06:01:16.000Z", "max_stars_repo_stars_event_max_datetime": "2019-09-09T06:01:16.000Z", "max_issues_repo_path": "couchdb/tdrepo/design/tdr/views/newestaip.js", "max_issues_repo_name": "crkn-rcdr/cihm-repomanage", "max_issues_repo_issues_event_min_datetime": "2019-06-10T16:12:41.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-02T16:26:42.000Z", "max_forks_repo_path": "couchdb/tdrepo/design/tdr/views/newestaip.js", "max_forks_repo_name": "c7a/cihm-repomanage", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 4, "max_forks_count": null, "avg_line_length": 29.6944444444, "max_line_length": 75, "alphanum_fraction": 0.506080449}
module.exports = {
  map: function(doc) {
    if (doc.type) {
      if (doc.type === "item_repository")
        emit(doc.owner, [doc["manifest date"], doc.repository]);
      else if (doc.type === "item")
        emit(doc._id, [doc["manifest date"], "item"]);
    }
  },
  reduce: function(keys, values, rereduce) {
    var maxdate;
    for (i = 0; i < values.length; i++) {
      if (!values[i] || values[i][0] === undefined) continue;
      if (!maxdate || values[i][0] > maxdate) {
        maxdate = values[i][0];
      }
    }
    if (maxdate) {
      var repolist = [];
      for (i = 0; i < values.length; i++) {
        if (!values[i] || values[i][0] === undefined) continue;
        if (values[i][0] === maxdate) {
          var myvalue=values[i][1];
          // If this is a rereduce, then the value will already be an array
          if (Array.isArray(myvalue)) {
            repolist=repolist.concat(myvalue);
          } else {
            repolist.push(myvalue);
          };
        }
      }
      if (repolist) return [maxdate, repolist];
    }
  }
};
