Created
May 18, 2024 15:36
Revisions
-
tanvirstreame created this gist
May 18, 2024 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,100 @@ class User { registerUser(userId, userName) { this.userId = userId; this.userName = userName; return "User Created"; } get() { return { userId: this.userId, userName: this.userName }; } } class Friend { constructor(follower, followee) { this.follower = follower; this.followee = followee; } addFriend(userId, friendId) { this.friends.push(userId, friendId) this.friends.push(friendId, userId) return "Added as friend" } removeFriend(userId, friendId) { this.friends = this.friends.filter(friend => !(friend.followee === userId && friend.follower === friendId)); this.friends = this.friends.filter(friend => !(friend.followee === friendId && friend.follower === userId)); return "Unfriended successfully"; } get() { return this.friends } } class Post { constructor(userId, posts) { this.userId = userId; this.posts = posts; this.postList = [] this.friends = [] } addPost(userId, posts) { this.postList.push(userId, posts); return "Added post successfully"; } getFriendPosts(userId) { const friend = new Friend(); this.friends.push(friend.get()) const friendList = this.friends.filter(eachUser => eachUser.follower === userId).map(friend => friend.followee) return this.postList.filter(post => friendList.includes(post.userId)) } searchFriendPosts(userId, search) { const friendList = this.friends.filter(eachUser => eachUser.follower === userId).map(friend => friend.followee) const postList = this.postList.filter(post => friendList.includes(post.userId)) return postList.filter(post => post.posts.toLowerCase().includes(search.toLowerCase())); } get() { return this.postList; } } const userList = []; const user1 = new User(); user1.registerUser(1, 'Tanvir') const user2 = new User(); user2.registerUser(2, 'Tanvir') userList.push(user1.get()); userList.push(user2.get()); const userInfo = user1.get(); console.log(userList,"userList") // const friend = new Friend(); // friend.addFriend(1, 2); // friend.removeFriend(1, 2) // friend.get(); // const post = new Post() // post.addPost(1, "bangal") // post.addPost(2, "banal") // post.getFriendPosts(1) // post.searchFriendPosts(1, "banal") // post.get(); // console.log("user", user.get()); // console.log("friend", friend.get()); // console.log("post", post.get());