For a project I have to do for school, I have to make an application that can sort appointments by date and time. I have an array with objects in them but can't figure out how to sort it by date as the date is nested.
Here is the bubblesort function I made:
function bubbleSort() {
const loop = listOfAppointments.length;
for(let i = 0; i < loop; i++) {
for(let j = 0; j < loop; j++) {
if(listOfAppointments[j] > listOfAppointments[j+1]) {
let temp = listOfAppointments[j];
listOfAppointments[j] = listOfAppointments[j+1];
listOfAppointments[j+1] = temp;
}
}
}
}
This function works fine with numbers, but I can't figure out how to sort the object using this function. I know there is a sort function in javascript, but we are not allowed to use it. The array I'm trying to sort looks like this:
[
{
"Appointment": {
"Id": 2,
"nameCustomer": "Henk Jan",
"addresdCustomer": "somethingstreet 34, middleofnowhere",
"time": "2020-01-07T10:00:00Z",
"reason": "gibberish"
}
},
{
"Appointment": {
"Id": 1,
"nameCustomer": "Jan Jaap",
"addresdCustomer": "somethingpavilion 54, middleofnowhere",
"time": "2020-01-07T12:15:00Z",
"reason": "gibberish"
}
},
{
"Appointment": {
"Id": 3,
"nameCustomer": "So Lost",
"addresdCustomer": "somethingthere 234, middleofnowhere",
"time": "2020-01-07T11:30:00Z",
"reason": "gibberish"
}
},
...
]
Thanks!
