include var declaration for i in indexGivenDates()

this was throwing an error for me in Google Apps Script