← Back to challenges

Jake's Meal Time

JavaScriptHardstringsarraysdates

Instructions

Jake is a very habitual person. He eats breakfast at 7:00 a.m. each morning, lunch at 12:00 p.m. and dinner at 7:00 p.m. in the evening.

Create a function that takes in the current time as a string and determines the duration of time before Jake's next meal. Represent this as an array with the first and second elements representing hours and minutes, respectively.

Examples

timeToEat("2:00 p.m.") ➞ [5, 0]
// 5 hours until the next meal, dinner

timeToEat("5:50 a.m.") ➞ [1, 10]
// 1 hour and 10 minutes until the next meal, breakfast

Notes

N/A

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.