Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a164843

Browse files
author
Andrew Mead
committed
Lesson: Storing Users: Part II
1 parent 46e4d97 commit a164843

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

chat-app/src/utils/users.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
const users = []
22

3-
// addUser, removeUser, getUser, getUsersInRoom
4-
53
const addUser = ({ id, username, room }) => {
64
// Clean the data
75
username = username.trim().toLowerCase()
@@ -40,15 +38,18 @@ const removeUser = (id) => {
4038
}
4139
}
4240

43-
addUser({
44-
id: 22,
45-
username: 'Andrew ',
46-
room: ' South Philly'
47-
})
48-
49-
console.log(users)
41+
const getUser = (id) => {
42+
return users.find((user) => user.id === id)
43+
}
5044

51-
const removedUser = removeUser(22)
45+
const getUsersInRoom = (room) => {
46+
room = room.trim().toLowerCase()
47+
return users.filter((user) => user.room === room)
48+
}
5249

53-
console.log(removedUser)
54-
console.log(users)
50+
module.exports = {
51+
addUser,
52+
removeUser,
53+
getUser,
54+
getUsersInRoom
55+
}

0 commit comments

Comments
 (0)