Event Scheduler
JavaScript
Medium
Objective
Write a function that sorts a list of events in chronological order
Requirements
Your function should be called
sortEvents
The function should take a single parameter, which is an array of events
Each event will contains:
date
: a string representing the event date in the format "YYYY-MM-DD".time
: a string representing the event time in the format "HH:MM".name
: a string representing the event name.
Your function should output an array of events sorted by:
Event
date
is ascending orderIf two events share the same
date
, they should be sorted bytime
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"}] |