🪟 Windows TippsHow to Enable Windows 11 Screen Savers(07.09.2026 um 12:41 Uhr)
🪟 Windows TippsMicrosoft Phone Link Not Showing Messages on Windows 11? Fix It(09.09.2026 um 07:52 Uhr)
⚠️ Malware / Trojaner / VirenPost-DEF CON phishing campaign delivered AMOS and NetSupport malware(24.08.2026 um 09:42 Uhr)
💾 IT Security ToolsHow to Use BloodHound Active Directory Setup Attack Path Analysis(10.09.2026 um 14:35 Uhr)
🕵️ SicherheitslückenCompliance Alert: EU Cyber Resilience Act 24-Hour Reporting Enforced(11.09.2026 um 06:25 Uhr)
🕵️ SicherheitslückenAWS IAM Privilege Escalation: Cheat Sheet And Defense(11.09.2026 um 07:43 Uhr)
🕵️ SicherheitslückenArista warns customers ahead of next week’s security disclosures(02.09.2026 um 23:34 Uhr)
🕵️ SicherheitslückenKARR Security vulnerability(02.09.2026 um 03:15 Uhr)
🪟 Windows TippsHow to Enable Windows 11 Screen Savers(07.09.2026 um 12:41 Uhr)
🪟 Windows TippsMicrosoft Phone Link Not Showing Messages on Windows 11? Fix It(09.09.2026 um 07:52 Uhr)
⚠️ Malware / Trojaner / VirenPost-DEF CON phishing campaign delivered AMOS and NetSupport malware(24.08.2026 um 09:42 Uhr)
💾 IT Security ToolsHow to Use BloodHound Active Directory Setup Attack Path Analysis(10.09.2026 um 14:35 Uhr)
🕵️ SicherheitslückenCompliance Alert: EU Cyber Resilience Act 24-Hour Reporting Enforced(11.09.2026 um 06:25 Uhr)
🕵️ SicherheitslückenAWS IAM Privilege Escalation: Cheat Sheet And Defense(11.09.2026 um 07:43 Uhr)
🕵️ SicherheitslückenArista warns customers ahead of next week’s security disclosures(02.09.2026 um 23:34 Uhr)
🕵️ SicherheitslückenKARR Security vulnerability(02.09.2026 um 03:15 Uhr)

🔧 Programmierung 🕛 vor 1 Jahr 14 Min Lesezeit
0

My first JavaScript package (with recursion for the win)

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

As I am a hobbyist developer who is still exploring the depths of JavaScript, and who had never written or published a package before, I am certainly in no position to teach anything to anyone. What I can do, though, is to share my experience in writing what is essentially still , where the final table ended up looking like this


































































Position Team Won Drawn Lost GF GA GD Points
1 Italy 2 0 1 3 1 +2 6
2 Belgium 2 0 1 4 2 +2 6
3 Republic of Ireland 1 1 1 2 4 -2 4
4 Sweden 0 1 2 1 3 -2 1


GF = Goals For (goals scored), GA = Goals Against (goals conceded), GD = Goal Difference.






Italy and Belgium are tied on points, and the first tiebreaker at the Euros is goal difference (where Italy and Belgium are still tied, with +2 each), followed by the number of goals scored—at which point one would expect Belgium to triumph over Italy, with 4 goals scored against 3.



However, the Euros are a competition where a head-to-head style is used to sort teams that are even on points. This means that, as soon as we recognize that Italy and Belgium need to have their tie broken, we immediately calculate a new sub-table made only of the teams concerned in the tie. And as they played a single match that ended 0-2 for Italy in the very first matchday, this sub-table looks like this (soccer assigns three points for a win, one for a draw and none for a loss)












































Position Team Won Drawn Lost GF GA GD Points
1 Italy 1 0 0 2 0 +2 3
2 Belgium 0 0 1 0 2 -2 0


GF = Goals For (goals scored), GA = Goals Against (goals conceded), GD = Goal Difference.






meaning that Italy is sorted above Belgium immediately, on account of head-to-head points (three to zero).



Different competitions will usually employ different styles (the Euros use the head-to-head style as we just saw, while for example the FIFA World Cup is famous for employing overall checks instead), though they will both switch to the other style should the first run of criteria be inconclusive in breaking a given tie.



This means that, potentially, head-to-head checks are bound to happen sooner or later (either immediately in a competition like the Euros, or as a potential second tiebreaking run at the FIFA World Cup). So my takeaway here was that the table we look at may potentially change during the sorting process, as the head-to-head style (whether it comes immediately or not) hinges on this fact.



But this was not my only takeaway, as the following example shows.






More intricacies: head-to-head reapplication



Belgium is once again the protagonist in the famous -d.), a recomputation of the head-to-head results does not happen at every step, but only once the full list of tiebreakers has run out. Since after the tie in points and goal difference there is still the number of goals scored to be checked, we look at that and this is why Romania ends up triumphing. Had that been tied as well, only at that point would we actually start considering a sub-table based on the single match played between the still-tied teams (Belgium and Romania), where Belgium would in fact come out on top due to their win.



So here is the second takeaway: there is a concept of depth involved in the sorting process, as depending on how far you are into it you have to take different decisions—such as whether to proceed with a sub-table recalculation or not. In this case, you would not proceed with it just yet as the list of criteria is still going on.



These are the main points that lead to my decision for the form of my sorting function.






A recursive approach



The sorting algorithm, accessing via the .standings() method of the class that my package implements, relies on a recursive function




CODE
const sortAndDivideTable = (table, iteration, criteria) => {
// ...
}





where at any given step table is the table holding the data of the teams that are currently to be sorted, iteration keeps track of the iteration number and other related information (e.g. if this is a head-to-head or overall type of check), and criteria is an array representing the ordered list of criteria to be applied (e.g. points, goal difference, number of goals scored).



The recursion starts with a table that is computed from all the matches played by all teams, and which is still potentially unordered. Notice that the first iteration of the algorithm is always of type overall (and is therefore initialized as such when the recursion starts), as by definition the first check is always the number of points obtained across all matches; again by definition, the first element in the criteria array is always "points".



This starting table is also safely kept tucked away: at any given step its entries are not modified, but its rows will be sorted little by little. For reference purposes, we can call it the ‘original standings’ from now on.





A real-world example from the UEFA Champions League



Having this in mind, it is possible to make sense of the algorithm with an example that is provided by / saw all teams finish their group with eight points each: how were these ties resolved? and who can say what happens at the Euros should two teams be equal on points, goal difference and goals…
















...and naturally, this is an opportunity for me to learn as well. If you see any points of concern or margins for improvement, do not be shy and tell me in the comments!

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
2 Quellen
Microsoft Phone Link Not Showing Messages on Windows 11? Fix It
1 Quelle
How to Enable Windows 11 Screen Savers
1 Quelle
Post-DEF CON phishing campaign delivered AMOS and NetSupport malware
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten My first JavaScript package (with recursion for the win)

Thematisch verwandte Begriffe: first, JavaScript, package, with · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...