var developers = [
{ name: "Joe", age: 23, overallLevel: "high", date: "Aug 14, 2015" },
{ name: "Sue", age: 28, overallLevel: "advanced", date: "Aug 11, 2015" },
{ name: "Jon", age: 32, overallLevel: "high", date: "Aug 10, 2015" },
{ name: "Bob", age: 24, overallLevel: "high", date: "Sept 07, 2015" },
{ name: "Johnson", age: 23, overallLevel: "advanced", date: "Aug 20, 2015" },
{ name: "Paul", age: 25, overallLevel: "basic", date: "Jan 30, 2016" },
{ name: "Jane", age: 27, overallLevel: "intermediate", date: "Aug 30, 2016" },
{ name: "Chris", age: 20, overallLevel: "basic", date: "Aug 1, 2016" },
{ name: "Susan", age: 25, overallLevel: "basic", date: "Dec 12, 2015" },
{ name: "Jenny", age: 23, overallLevel: "intermediate", date: "Aug 30, 2016" },
{ name: "Stone", age: 25, overallLevel: "basic", date: "June 13, 2016" },
]
以下是从数组中提取的数据,这些数据表示级别及其日期。
“高”:2015 年 8 月 10 日、2015 年 8 月 14 日、2015 年 9 月 7 日
“高级”:2015 年 8 月 11 日、2015 年 8 月 20 日
“基本”:2016 年 1 月 30 日,2016 年 8 月 1 日,2015 年 12 月 12 日,2016 年 6 月 13 日,
“中级”:2016 年 8 月 30 日、2016 年 8 月 30 日
预期输出:需要最小和最大日期的范围,即进一步显示
{ 高:2015 年 8 月 10 日 - 2015 年 9 月 7 日,高级:2015 年 8 月 11 日 - 2015 年 8 月 20 日,基本:2015 年 12 月 12 日 - 2016 年 8 月 1 日,中级:2016 年 1 月 30 日}
这就是我能够获得用于分组目的的整体级别的计数。
var developers = [
{ name: "Joe", age: 23, overallLevel: "high", date: "Aug 14, 2015" },
{ name: "Sue", age: 28, overallLevel: "advanced", date: "Aug 11, 2015" },
{ name: "Jon", age: 32, overallLevel: "high", date: "Aug 10, 2015" },
{ name: "Bob", age: 24, overallLevel: "high", date: "Sept 07, 2015" },
{ name: "Johnson", age: 23, overallLevel: "advanced", date: "Aug 20, 2015" },
{ name: "Paul", age: 25, overallLevel: "basic", date: "Jan 30, 2016" },
{ name: "Jane", age: 27, overallLevel: "intermediate", date: "Aug 30, 2016" },
{ name: "Chris", age: 20, overallLevel: "basic", date: "Aug 1, 2016" },
{ name: "Susan", age: 25, overallLevel: "basic", date: "Dec 12, 2015" },
{ name: "Jenny", age: 23, overallLevel: "intermediate", date: "Aug 30, 2016" },
{ name: "Stone", age: 25, overallLevel: "basic", date: "June 13, 2016" },
],
overallLevel = developers.reduce(function (r, a) {
r[a.overallLevel] = (r[a.overallLevel] || 0) + 1;
return r;
}, {});
console.log(overallLevel);