Last active
December 29, 2020 05:50
-
-
Save Santiago-j-s/277c1c3b445e5fd4c4598f92e15d40ce to your computer and use it in GitHub Desktop.
you don't know js exercises
This file contains hidden or 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
| function validTime(time) { | |
| return time.match(/\d?\d:\d?\d/) !== null; | |
| } | |
| function toMinutes(time) { | |
| if (!validTime(time)) { | |
| throw 'time must be of format hh:mm'; | |
| } | |
| const parts = time.split(":"); | |
| const hours = Number.parseInt(parts[0]); | |
| const minutes = Number.parseInt(parts[1]); | |
| return hours * 60 + minutes; | |
| } | |
| const dayStart = "07:30"; | |
| const dayEnd = "17:46"; | |
| function scheduleMeeting(startTime, durationMinutes) { | |
| const meetingStart = toMinutes(startTime); | |
| const meetingEnd = meetingStart + durationMinutes; | |
| const startInTime = meetingStart >= toMinutes(dayStart); | |
| const endInTime = meetingEnd <= toMinutes(dayEnd); | |
| return startInTime && endInTime; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment