Sort the data according to sortingOrder Problem #3
Question: Sort the data according to sortingOrder.
let data = [
{ day: "Friday", hours: ["5:00pm to 12:00am"] },
{ day: "Wednesday", hours: ["5:00pm to 11:00pm"] },
{ day: "Sunday", hours: ["11:00am to 11:00pm"] },
{ day: "Thursday", hours: ["5:00pm to 11:00pm"] },
{ day: "Saturday", hours: ["11:00am to 12:00am"] }
];
const sortingOrder = {
"monday": 1,
"tuesday": 2,
"wednesday": 3,
"thursday": 4,
"friday": 5,
"saturday": 6,
"sunday": 7
}
Answer:
let updatedData = [];
for(item of data){
updatedData[sortingOrder[item['day'].toLowerCase()]] = item;
}
updatedData.sort();
console.log(updatedData);