include var declaration for i in indexGivenDates()

this was throwing an error for me in Google Apps Script.  You may want to put this into a var declaration at the top of the function, instead of at the for loop