1
var Twitter = function () {2
this.users = new Map();6
Twitter.prototype.postTweet = function (userId, tweetId) {7
if (!this.users.has(userId)) this.users.set(userId, new Set());8
this.tweets.push({ userId, tweetId });11
Twitter.prototype.getNewsFeed = function (userId) {12
let user = this.users.get(userId);13
let recentTweets = [];15
let i = this.tweets.length - 1;16
i >= 0 && recentTweets.length < 10;19
if (user.has(this.tweets[i].userId) || this.tweets[i].userId === userId) {20
recentTweets.push(this.tweets[i].tweetId);26
Twitter.prototype.follow = function (followerId, followeeId) {27
let user = this.users.get(followerId) || new Set();29
this.users.set(followerId, user);32
Twitter.prototype.unfollow = function (followerId, followeeId) {33
this.users.get(followerId)?.delete(followeeId);