0

So basically I got the following assignment:

    Returns the number of open timeslots in the given list of appointments.
    Given appointments [9:30-10:00, 12:00-13:00, 15:15-16:30]
    the result should be 4
    [8:00-9:30, 10:00-12:00, 13:00-15:15, 16:30-17:00].
    name="appointments">The list of current appointments
    The number of open timeslots in the given list of appointments

What is the best way to check for open slots, without using a lot of IF statements? This is what I got so far:

        public int GetNumberOfOpenTimeslots(Appointment[] appointments)
        {
            int openslots = 0;
            foreach (var t in appointments)
            {
                if (t.End > t.Start )
                {
                    openslots++;
                }
            }

            return openslots;
        }

NOTE: "Appointmens[]" contains a list with all the appointments.

Anonymous Asked question May 14, 2021