Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Immutable State Update

Modern JavaScriptmedium

Course · Section 17: Modern JavaScript Development: Modules, Tooling, and Functional · Lecture 294: Declarative and Functional JavaScript Principles

Implement `updateScore(state, points)` returning a new state object with `score` increased by `points`, without mutating the original.

Sample tests

Input: updateScore({"score":10}, 5)
Output: {"score":15}
Input: updateScore({"score":0,"level":1}, 3)
Output: {"score":3,"level":1}

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • state.score += points mutates the original object.
Approach & explanation (try first)

Spreading into a new object with an updated score keeps the update immutable.

Loading...
⌘/Ctrl + Enter

Run your code to see results.