Last active
April 5, 2024 06:18
-
-
Save aceofspades19/a1d1580443195f2f0a5ed55d7b3ba810 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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