March 2018
Intermediate to advanced
592 pages
13h 44m
English
Over inside user.js, we can get started by finding the user, if any. That means, we're going to use a similar technique to what we have in the getUser method. I'm going to actually copy the following line from the getUser method and paste it just right inside of removeUser:
return this.users.filter((user) => user.id === id) [0]
Creating a variable called user, setting it equal to the preceding line. Now you could also go ahead and actually call getUser. I could call this.getUser, passing in id just like this:
removeUser (id) {
var user = this.getUser(id);
}
Both of those solutions are going to work as expected. Next up, if there is a user, we want to remove it, if(user), we're going to do something special, and ...