Created
June 6, 2019 23:24
-
-
Save arturovt/3451a85e5577eea76ef377354cef019a 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 userToRemoveIndex = this.users.indexOf(user); | |
this.users = this.users.filter((_, index) => { | |
return index !== userToRemoveIndex; | |
}); // BAD | |
this.users = [ | |
...this.users.slice(0, userToRemoveIndex), | |
...this.users.slice(userToRemoveIndex + 1) | |
]; // BAD | |
const users = this.users.slice(); | |
users.splice(userToRemoveIndex, 1); | |
this.users = users; // GOOD, we also change the reference |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment