var data = [
'08-10-2011',
'08-04-2007',
'03-11-2008',
...
'03-28-2005'
];
var date = {
'2002' : {
'04' : ['01', '10', '14', '18', '27'],
'05' : ['03', '09']
},
'2003' : {
'11' : ['01', '15', '21', '22'],
'12' : ['05', '28', '31']
},
...
'2015' : {
'02' : ['04', '15'],
'03' : ['09', '26', '28']
}
};
var data = [
'08-10-2011',
'08-04-2007',
'03-11-2008',
'03-03-2008',
'03-14-2008',
'03-28-2005',
'03-20-2005'
];
function decodeDate(arr) {
var i, len = data.length,
obj = {},
date,
year,
month;
for (i = 0; i < len; i++) {
date=arr[i].split("-");
if(!obj[year=date[2]])obj[year]={};
if(!obj[year][month=date[0]]){
obj[year][month]=[date[1]];
}else{
obj[year][month].push(date[1]);
}
}
return obj;
}
console.log(decodeDate(data));