I have data that comes from my server to datatables. I'm successfully populating my table but in footer callback I want to do some statistics.
Lets say I have data like so:
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"
}];
I would like to count number of days with different holidays.
Here is result I would like to get:
var summary= [
{
    "One type of holiday": {
        "work": 0,
        "weekend": 1
    }
},
{
    "Another type": {
        "work": 1,
        "weekend": 1
    }
}];
I've created a very simple code to simply aggregate holidays:
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;
}
but this gives me invalid results, because in my data array holiday contains spaces.
I need a way to fix this and to split holidays based on dayType.
MY SOLUTION: My version of answer:
var summary = {}, d, tmp, type;
for (var i = 0; i < data.length; i++) {
    var d = data[i];
    if (d.holiday.length > 0) {
        type = d.dayType == 'Weekend' || d.dayType == 'Free' ? 'Weekend' : 'Work';
        tmp = summary[d.holiday];
        if (!tmp) {
            tmp = {
                Weekend: 0,
                Work: 0
            };
            summary[d.holiday] = tmp;
        }
        summary[d.holiday][type] += 1;
    }
}
Because this is modified version of @Arun answer I'm not posting this as standalone answer.
I find my version easier to understand, hope someone find's it useful.
 
     
     
     
    