Skip to content

Instantly share code, notes, and snippets.

@Santiago-j-s
Last active December 29, 2020 05:50
Show Gist options
  • Select an option

  • Save Santiago-j-s/277c1c3b445e5fd4c4598f92e15d40ce to your computer and use it in GitHub Desktop.

Select an option

Save Santiago-j-s/277c1c3b445e5fd4c4598f92e15d40ce to your computer and use it in GitHub Desktop.
you don't know js exercises
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