MediumPro challengeTypeScript

Mediator

TypeScriptDesign PatternsBehavioralMediator

Have objects communicate through a central mediator instead of referencing each other directly — a chat room, not a mesh of direct user-to-user connections.

Implement `ChatRoomMediator.send(from, text)`: deliver the message to every registered user except the sender, logging each delivery.

solve(messages, users) registers each user with the mediator, sends every message, and returns the delivery log.

solve([{ from: 'alice', text: 'hi' }], ['alice', 'bob'])[{ to: 'bob', from: 'alice', text: 'hi' }]

Sample tests

Test #1Two users, one message
Input: [[{"from":"alice","text":"hi"}],["alice","bob"]]
Output: [{"to":"bob","from":"alice","text":"hi"}]
Test #2Broadcast to all other users
Input: [[{"from":"alice","text":"hi"}],["alice","bob","carol"]]
Output: [{"to":"bob","from":"alice","text":"hi"},{"to":"carol","from":"alice","text":"hi"}]
Test #3No messages
Input: [[],["alice","bob"]]
Output: []