Skip to content

Instantly share code, notes, and snippets.

@maximelkin
Created November 25, 2018 11:33
Show Gist options
  • Save maximelkin/4e56cdff9890e8c5a27443cfd3a6d270 to your computer and use it in GitHub Desktop.
Save maximelkin/4e56cdff9890e8c5a27443cfd3a6d270 to your computer and use it in GitHub Desktop.
const step = 24 * 60 * 60 * 1000;
function findMissed(values) {
const dates = values.map(x => new Date(x.date).getTime());
const sum = dates.reduce((acc, x) => acc + x);
const min = Math.min(...dates);
return new Date((min * (dates.length + 1) + step * (dates.length + 1) * dates.length / 2) - sum).toISOString().split('T')[0];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment