I am looking at this specific answer.
What is the reason behind Code Snippet 2 not producing the same result as Code Snippet 1?
Code Snippet 1:
var firstEvents = events.reduce(function(ar, e) {
var id = e.getId();
if (e.isRecurringEvent() && e.isAllDayEvent() && !ar.some(function(f) {return f.eventId == id})) {
ar.push({eventTitle: e.getTitle(), eventId: id, startDate: e.getAllDayStartDate(), endDate: e.getAllDayEndDate()});
}
return ar;
}, []);
Code Snippet 2:
var firstEvents = events.reduce(function(ar, e) {
var id = e.getId();
if (e.isRecurringEvent() && e.isAllDayEvent() && !ar.some(function(f) {return f.eventId == id})) {
ar['eventTitle'] = e.getTitle();
ar['eventId'] = id;
ar['startDate'] = e.getAllDayStartDate();
ar['endDate'] = e.getAllDayEndDate();
}
return ar;
}, []);
EDIT:
Why does Code Snippet 3 work as expected (adding one object per event series) while Code Snippet 4 fails to do so?
Code Snippet 3:
var firstEvents = events.reduce(function(ar, e) {
var id = e.getId();
if (e.isRecurringEvent() && e.isAllDayEvent() && !ar.some(function(f) {return f.eventId == id})) {
ar.push({eventTitle: e.getTitle(), eventId: id});
}
return ar;
}, []);
Code Snippet 4:
var firstEvents = events.reduce(function(ar, e) {
var id = e.getId();
if (e.isRecurringEvent() && e.isAllDayEvent() && !ar.some(function(f) {return f.eventId == id})) {
ar.push({eventTitle: e.getTitle()});
}
return ar;
}, []);