Filling the removeUser method

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 ...

Get Advanced Node.js Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.