Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(arr) {
- let chat = [];
- for (let line of arr) {
- let tokens = line.split(' ');
- let command = tokens[0];
- let message = tokens[1];
- if (command === 'Chat') {
- chat.push(message);
- } else if (command === 'Delete') {
- chat = chat.filter(x => x !== message);
- } else if (command === 'Edit') {
- let newMessage = tokens[2];
- chat.map((x, i, chat) => x === message ? chat[i] = newMessage : chat[i] = x);
- } else if (command === 'Pin') {
- let messagesToPin = chat.filter(x => x === message);
- chat = chat.filter(x => x !== message);
- chat.push(...messagesToPin);
- } else if (command === 'Spam') {
- chat.push(...tokens.slice(1));
- }
- }
- console.log(chat.join('\n'));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement