Rename User (Immutable Update)
When updating items inside an array, prefer immutable updates: create a new array and, for the matching item, return a new object with the change. This avoids surprising side effects.
You’ll rename a user identified by id without mutating the input array or any existing user objects.
Your Task
- Complete renameUser(users: { id: number; name: string }[], id: number, newName: string): { id: number; name: string }[].
- Return a new array.
- For the matching user, return a new object with the updated name.
- Leave all other users unchanged (same references are fine).
Examples
- renameUser([{ id: 1, name: 'Ada' }], 1, 'Lin') → [{ id: 1, name: 'Lin' }]
- renameUser([{ id: 1, name: 'Ada' }], 2, 'Lin') → [{ id: 1, name: 'Ada' }]