I have the following code below however ESlint doesn't like it giving
Function declared in loop contains unsafe references to variable 'result'
How can I rewrite this to remove that problem? I'm trying to use "result" to return result of function.
const checkEventOverlap1 = (sectionsToUpdate) => {
var i;
let result = false;
for(i = 0; i < sectionsToUpdate.length; i++){
const firstSelectedEventStartTime = new Date(sectionsToUpdate[i].recurrence.timePeriod.startOn);
const firstSelectedEventRelatedCourse = sectionsToUpdate[i].section16.course16.id;
const selectedEventDays = sectionsToUpdate[i].recurrence.repeatRule.daysOfWeek;
const removedSection = sectionsToUpdate.splice(i, 1);
sectionsToUpdate.forEach(sectionToUpdate => {
const previousEventDays = sectionToUpdate.recurrence.repeatRule.daysOfWeek;
const previousEventRelatedCourse = sectionToUpdate.section16.course16.id;
const eventStartTime = new Date(sectionToUpdate.recurrence.timePeriod.startOn);
const eventEndTime = new Date(sectionToUpdate.recurrence.timePeriod.endOn);
// Ensure days dont clash (eg Monday = Monday), if they do then there is a clash possibilty
if(previousEventDays.some(day => selectedEventDays.includes(day)) && previousEventRelatedCourse !== firstSelectedEventRelatedCourse){
// We have a day match now check if there is a time clash, if so we have an overlap so set result to true
if((eventStartTime <= firstSelectedEventStartTime || eventStartTime >= firstSelectedEventStartTime) && firstSelectedEventStartTime <= eventEndTime){
console.log("yup");
result = true;
}
}
});
sectionsToUpdate.splice(i, 0, removedSection[0]);
console.log(sectionsToUpdate);
}
return result;
};