Last active
January 12, 2022 02:09
-
-
Save ancyrweb/6f0a7f80434a7aa87f012bdf81205d52 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const users = [ | |
{ | |
name: "Jane", | |
balance: 100, | |
}, | |
{ | |
name: "John", | |
balance: 75, | |
}, | |
{ | |
name: "Ellis", | |
balance: 31.3, | |
}, | |
]; | |
const double = (amount) => amount * 2; | |
const indexToUpdate = 1; // we will change user at index 1 only | |
const nextUsers = users.map((user, index) => | |
index === indexToUpdate ? { ...user, balance: double(user.balance) } : user | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment