Проблем относно сортирането в изпита JS Advanced Exam - 24 Oct 2020
В условието на задачата пише следното:
If there is another Lecture with the same Module:
The lectures should be sorted by DATE! The date is separated with slashes (/) and the separator between the date and time is a minus sign.
Hint: The format of the date allows alphabetical sort.
Не мога да открия начин, по който да сортирам лекциите по дата. Кода ми е следния:
function solve() {
let lectureName = document.getElementsByName("lecture-name");
let lectureDate = document.getElementsByName("lecture-date");
let lectureModule = document.getElementsByName("lecture-module");
let addButton = document.querySelector("button");
addButton.addEventListener('click', e => {
e.preventDefault();
let date = lectureDate[0].value.replaceAll("-", "/");
date = date.replaceAll("T", " - ");
let divModules = document.getElementsByClassName("modules");
let div = "";
if (document.getElementById(lectureModule[0].value)) {
div = document.getElementById(lectureModule[0].value);
} else {
div = document.createElement("div");
div.classList.add("module");
div.id = lectureModule[0].value;
let h3 = document.createElement("h3");
h3.innerHTML = lectureModule[0].value;
div.appendChild(h3);
}
let ul = document.createElement("ul");
let li = document.createElement("li");
li.classList.add("flex");
let h4 = document.createElement("h4");
h4.innerHTML = `${lectureName[0].value} - ${date}`; //Arrays - 2020//09/17 - 18:00
let button = document.createElement("button");
button.classList.add("red");
button.innerHTML = "Del"; //[Del]
li.appendChild(h4);
li.appendChild(button);
ul.appendChild(li);
div.appendChild(ul);
divModules[0].appendChild(div);
button.addEventListener('click', e => {
e.preventDefault();
div.removeChild(ul);
if (div.childElementCount === 1) {
divModules[0].removeChild(div);
}
})
})
};
Линк към изпита: https://judge.softuni.bg/Contests/Practice/Index/2590#0
Благодаря за помощта!