Monday’s rotation is done. Marta has moved to the back, and the rota now reads Dev, Sam, Ines, Kofi, Bea, and Marta. The script’s next job is the team channel post naming who’s on call for the next three weeks. In Python, you get those names with a slice, written with square brackets and colons.
JavaScript has no slice syntax for arrays. It reads ranges with a method instead, and that raises a question you’ll ask of every array method from here on: Does this change my array? You’ll take the next three weeks, the back of the queue, and a reversed rota, all without touching the rota itself.
Take a Range With .slice()
The Python script builds the team channel line from the first three names, joined with a comma and a space:
rota = ["Dev", "Sam", "Ines", "Kofi", "Bea", "Marta"]
print(f"Next three weeks: {', '.join(rota[:3])}")
In the JavaScript port, the slice becomes a call to .slice() with the start and end positions as arguments:
const rota = ["Dev", "Sam", "Ines", "Kofi", "Bea", "Marta"];
const nextThree = rota.slice(0, 3);
console.log(`Next three weeks: ${nextThree.join(", ")}`);
console.log(rota.join(", "));
Run it, and the console shows the same line the Python script printed, while the rota keeps all six names in their Monday order: