When you access any football game that is on the live list on this website, if you click on the name of the game, a drop-down selection box will appear with all the other live matches.
I’m trying to put all the matches together and ordered from those with the most minutes played to those with the fewest minutes played, all the values are in time strings, but when I try to organize them, notice that in the image not all of them are organized, some are in the wrong place not sorted:
The code I created should collect the complete element of each game if it has the time string, create a list and then organize them according to the time value and I would place them all within a block of the first competition that is listed:
const fixtureElements = document.querySelectorAll('.ipn-CompetitionContainer');
let fixturesWithTime = [];
fixtureElements.forEach(fixtureElement => {
const timeElement = fixtureElement.querySelector('.ipn-Fixture_TimerContainer');
const timeValue = timeElement.textContent.trim();
fixturesWithTime.push({ fixtureElement, timeValue });
});
fixturesWithTime.sort((a, b) => {
return b.timeValue.localeCompare(a.timeValue);
});
const targetElement = document.querySelector('.ipn-Competition');
fixturesWithTime.forEach(item => {
targetElement.appendChild(item.fixtureElement);
});
What is happening that this organization is not 100% correct and some games are in the wrong place on the list?