Filling the getUser

I'm going to start off with getUser, the goal here is to return the user object whose ID matches the ID of argument passed in getUser. To get that done, I am going to be using filter. We're going to return the result from this.users.filter, we're going to be filtering by ID, and here we filter by room. We're going to pass in our arrow function using the expression syntax, the argument will be user, and we are going to go ahead and return true if the user's id property equals the ID of the argument. If that is the case, we do want to keep this user in the array. And in the end, we should have just one user or 0 users, and all we're going to do is return the first item:

getUser (id){ return this.users.filter((user) => user.id ...

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.