I have recently been stuck on what I think should be a fairly simple problem.
Basically I have weekdays represented as a number (1-7) representing Monday to Sunday.
I need a function that has this prototype:
function weekday_between(weekday, start_weekday, end_weekday) {
//if the weekday is between start and end then return true, otherwise return false
...
}
The main issue I am having is when the start_weekday is greater than the end_weekday, since I don’t think you can just rely on a nested if statement (?).
For example:
weekday_between(2, 1, 3) //return true
weekday_between(1, 7, 2) //return true, the hard part
weekday_between(2, 7, 1) //return false
weekday_between(6, 7, 1) //return false
The project is in php but pseudocode is fine, or even just a point in the right direction.
1 Answer