Get an array of date values from dataset, and based on the values, filter a date array, to get the ones available

Can I take a look at this getDates() function? Can you show me if there is any error?