Skip to content

Instantly share code, notes, and snippets.

@mantismamita
Last active May 11, 2022 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mantismamita/3f364280b23967aa955e1129d7aebb6b to your computer and use it in GitHub Desktop.
Save mantismamita/3f364280b23967aa955e1129d7aebb6b to your computer and use it in GitHub Desktop.
js algorithm utility functions
// greatest common denominator
const gcd = (a, b) => b ? gcd(b, a % b) : a
// lowest common multiplier
const lcm = (a, b) => (a * b)/ gcd(a, b)
// some Date stuff for safe-keeping
const weekdayMonthFormat = {
weekday: 'long',
day: 'numeric',
month: 'long',
timeZone: 'Europe/Paris',
} as Intl.DateTimeFormatOptions;
const getFrenchMonths = () => {
const now = new Date(Date.now());
const availableDates = [];
for (let i = (-1 * 7); i <= 0; i++) {
const tempDate = new Date(Number(now));
tempDate.setDate(now.getDate() + i);
tempDate.setHours(12);
const tempTime = ~~(tempDate.getTime() / 1e3);
availableDates.push(getDateFromTimestamp(tempTime, weekdayMonthFormat));
}
return availableDates;
};
const getMidnightOfTimestamp = (time: number): number => {
const midnight = new Date(time * 1e3).setHours(0, 0, 0, 0);
return midnight / 1e3;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment