Skip to content

Instantly share code, notes, and snippets.

@aceofspades19
Last active April 5, 2024 06:18
Show Gist options
  • Save aceofspades19/a1d1580443195f2f0a5ed55d7b3ba810 to your computer and use it in GitHub Desktop.
Save aceofspades19/a1d1580443195f2f0a5ed55d7b3ba810 to your computer and use it in GitHub Desktop.
// Inspired by 'alexismenest' capstone 'mockAPI' logic.
// fetchAPI accepts a JavaScript Date object.
// fetchAPI returns a list of randomly generated available times.
// The times are between 15:00 and 23:30.
// The list always begins with "--- Select a Time---"
// I found this useful for debugging.
//
// submitAPI always returns 'true'.
const seededGenerator = (date, hour) => {
const m = 9;
const d = date.getDate();
const result = ((d + hour) % m ) / 10;
return result;
}
const fetchAPI = (date) => {
let result = [];
result.push("--- Select a Time ---")
for (let hour = 15; hour <= 23; hour++) {
if(seededGenerator(date, hour) < 0.5) result.push(hour + ':00');
if(seededGenerator(date, hour + 7) < 0.5) result.push(hour + ':30');
}
return result;
};
const submitAPI = formData => true;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment