Event Scheduler

JavaScript
Medium

Objective

Write a function that sorts a list of events in chronological order

Requirements

  1. Your function should be called sortEvents

  2. The function should take a single parameter, which is an array of events

  3. Each event will contains:

    1. date: a string representing the event date in the format "YYYY-MM-DD".

    2. time: a string representing the event time in the format "HH:MM".

    3. name: a string representing the event name.

  4. Your function should output an array of events sorted by:

    1. Event date is ascending order

    2. If two events share the same date, they should be sorted by time in ascending order

Starting code

const testEvents = [ { date: "2023-10-01", time: "14:00", name: "Lunch" }, { date: "2023-10-02", time: "13:00", name: "Shopping" }, { date: "2023-10-02", time: "17:00", name: "Dinner" } ];

Check your solution

Tests

Function name is sortEvents
sortEvents([{date:"2023-10-02",name:"Dinner",time:"17:00"},{date:"2023-10-01",name:"Lunch",time:"14:00"},{date:"2023-10-02",name:"Shopping",time:"13:00"}])Expected:[{"date":"2023-10-01","name":"Lunch","time":"14:00"},{"date":"2023-10-02","name":"Shopping","time":"13:00"},{"date":"2023-10-02","name":"Dinner","time":"17:00"}]