Correcting Results With with() and toSpliced()

The week 9 table is ranked. Then the messages start. United’s captain says the Dynamo game finished 3-2, not 3-1, and the committee may yet void Athletic 2-2 Wanderers. Nadia’s results are fixed—a tuple in Python and a frozen array in the port—and they should stay that way because they’re what the captains reported.

So the script needs corrected results that leave the reported ones alone. In this lesson, you’ll ask JavaScript for changed copies of an array, frozen or not.

Ask for a Changed Copy

In Python, RESULTS is a tuple of tuples, so you can’t assign to its elements. Nadia builds new tuples from slices of the old one—one with the corrected match at the end and one without the Athletic draw:

Language: Python
RESULTS = (
    ("Rovers", 4, "Albion", 1),
    ("Athletic", 2, "Wanderers", 2),
    ("Dynamo", 3, "United", 1),
)
corrected = RESULTS[:2] + (("Dynamo", 3, "United", 2),) + RESULTS[3:]
counted = RESULTS[:1] + RESULTS[2:]
print(corrected[2])
print(counted)

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.