Congratulations, you made it to the end of the course! The team lead’s Monday script now runs in JavaScript. monday-rota.js moves Marta to the back of the queue, takes Sam off for his leave, puts Lena in straight after Dev, and posts the same lines to the team channel as the Python script, starting with “On call this week: Dev”.
Every step of that script is an array operation, and none of them needs a loop. In this course, you learned how to:
- Build the rota as an array and read it with
rota[0],rota.at(-1), and.length, sincerota[-1]quietly givesundefined - Add and remove at the ends with
.push(),.pop(),.shift(), and.unshift(), sorota.push(rota.shift())rotates the queue - Hold a pair like the out-of-hours window in an array,
[18, 8], or in an object,{ start: 18, end: 8 }, where Python uses a tuple - Take copies with
.slice(),.toReversed(), and.concat(), from the next three weeks to the escalation list - Change an array in place with
.splice(), which removes Sam withrota.splice(1, 1)and inserts Lena withrota.splice(1, 0, "Lena") - Search with
.includes()and.indexOf(), and check for-1before you splice - Sort a copy with
.toSorted(), passing(a, b) => a - bfor numbers or(a, b) => b - afor the busiest weeks first
Keep the Habits That Carry Over
Much of what you know about lists still holds. Positions start at zero, and .slice() follows Python’s slicing rules, stopping before the end position and counting negative positions from the back, though it takes no step. The default sort orders plain names as Python’s does, so the HR wiki gets “Bea, Dev, Ines, Kofi, Lena, Marta” in both languages.