Loading video player…

Welcome to the League Table

This course is about copying, freezing and sorting data the JavaScript way. Your project is to port the league table script of Nadia, volunteer secretary of the Eastgate Leisure Centre’s Thursday-night five-a-side league.

Here’s a first taste. Nadia’s Python script keeps the week’s results provisional in a deep copy, not the confirmed table, then prints each team’s move. Here’s the copy step, with the rest of the script folded:

Language: Python
import copy

# POINTS, table, RESULTS and the helpers

provisional = copy.deepcopy(table)
for home, home_goals, away, away_goals in RESULTS:
    ...

# print the table, each move and the leaders

Python prints two teams up one place and two down one, and the confirmed leaders are still Athletic:

Language: Program Output
Week 9 table (provisional)
1. Rovers 16 pts, form LDWLW, up 1
2. Athletic 16 pts, form WDWWD, down 1
3. Dynamo 13 pts, form LWDLW, up 1
4. Wanderers 13 pts, form DLWWD, down 1
5. United 9 pts, form WLLWL, same
6. Albion 7 pts, form LDWLL, same
Confirmed leaders: Athletic

Here’s the JavaScript port of the same step, line for line, with the copy made with spread:

Language: JavaScript
// POINTS, table, RESULTS and the helpers

const provisional = [...table];
for (const match of RESULTS) {
  // ...
}

// print the table, each move and the leaders

It runs with no error and prints this:

Language: Program Output
Week 9 table (provisional)
1. Rovers 16 pts, form LDWLW, same
2. Athletic 16 pts, form WDWWD, same
3. Dynamo 13 pts, form LWDLW, same
4. Wanderers 13 pts, form DLWWD, same
5. United 9 pts, form WLLWL, same
6. Albion 7 pts, form LDWLL, same
Confirmed leaders: Rovers

Every move says same, and the confirmed leaders are Rovers, where Python says Athletic. A line-for-line port can run without an error and quietly give a different answer, and this course shows you where, and what JavaScript does instead.

Six teams play each Thursday, and the league committee confirms each week’s results. The center’s booking site runs on Node, so you’ll port Nadia’s script.

By the end of this course, you’ll be able to:

  • Copy arrays, records, Maps and Sets where Python uses table.copy() and {**rovers}, and make a copy that really is separate from its original
  • Make tuple-like data read-only with Object.freeze()
  • Sort records with compare functions where Python passes key=, and rank teams that are level on points
  • Change a copy, not the original, with with(), toSpliced() and toSorted()
  • Put Nadia’s whole script together in JavaScript

You only need to know Python’s copies, tuples and sort keys: shallow and deep copies, tuples as records that can’t change, and sorting with a key function. In JavaScript, you only need to know how to write small programs with arrays of objects, functions and arrow functions, copy an array with slice(), sort numbers with a compare function, and use Map and Set.

A current version of Node and of Python is fine: the examples use Node 26 and Python 3.15.

The course mixes short videos and text lessons, with exercises where you write the code yourself. Every video has notes below it, so you can review without rewatching. A project puts Nadia’s whole script together, and a quiz and a summary close the course.

Next up: Copying Arrays and Records With Spread, where you copy the confirmed table and Rovers’ record the JavaScript way, and copy Maps and Sets with their own constructors.

Download

Sample Code (.zip)

11.2 KB
Download

Course Slides (.pdf)

812.3 KB

00:00 Welcome to Copying, Freezing, and Sorting JavaScript Arrays for Pythonistas! This course is about copying, freezing and sorting data the JavaScript way. Your project: port the league table script of Nadia, secretary of a five-a-side league.

00:16 Each week’s results stay provisional until the league committee confirms them. Here’s a first taste. Her Python script keeps results provisional in a deep copy, not the confirmed table, and prints each team’s move.

00:32 The JavaScript port copies with spread, runs with no error, and prints this. Every move says same. And the confirmed leaders are Rovers, where Python says Athletic.

00:48 A line-for-line port can run without an error and quietly give a different answer. This course shows you where, and what JavaScript does instead.

00:59 Six teams play each Thursday, and the league committee confirms each week’s results. The center’s booking site runs on Node, so you’ll port Nadia’s script.

01:11 By the end, you’ll copy arrays and records, freeze what mustn’t change, sort records, and change copies, not originals. Then the project ports Nadia’s whole script.

01:25 You only need to know Python’s copies, tuples and sort keys, and enough JavaScript to work with arrays of objects, functions, Maps and Sets, copy an array with slice(), and sort numbers with a compare function.

01:39 Short videos mix with text lessons and exercises. A project, a quiz and a summary close the course. Next up is Copying Arrays and Records With Spread, a text lesson that starts by putting Rovers’ win into a copy.

Become a Member to join the conversation.