array agregation

by mithunsatheesh

JavaScript

var data = [{
    date: '2013-05-12',
    holiday: "One type of holiday",
    dayType: "Weekend"
}, {
    date: '2013-05-13',
    holiday: "Another type",
    dayType: "Weekend"
}, {
    date: '2013-05-14',
    holiday: "Another type",
    dayType: "Work"
}, {
    date: '2013-05-15',
    holiday: "",
    dayType: "Work"
}];


var summary = [];

for (var i = 0; i < data.length; i++) {
    //console.log(data[i].holiday);
    /*other stuff here*/
    if (data[i].holiday.length > 0) 
        summary[data[i].holiday] = summary[data[i].holiday] + 1 || 1;
}
console.log(summary);
console.log(summary.length);
console.log(Object.keys(summary).length);