I have up to 7 integers representing each day of the week 0 ... 6
(sun - sat)
The current day = 3
(wednesday).
How can I reorder array of integers so that the number closest to Wednesday (3
) comes first.
For example:
Current Day = 3
Days (input) = [0, 1, 2, 3, 4, 5, 6]
Correct Output = [3, 4, 5, 6, 0, 1, 2]
But the array may not contain all days (for example current day
might be missing):
Current Day = 3
Days (input) = [0, 2, 4, 6]
Correct Output = [4, 6, 0, 2]
Basically reorder the array so that the current day
comes first (or the integer that preceeds it)
Current Attempt: I've looked into using a.rotate but I'm unsure how to deal with if the current day
is not in the array.
I've also tried using min_by
but it does not loop integers
@days.min_by { |x| (x.to_f - Time.now.wday).abs }