Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- roliTheCoder = (input) => {
- let pattern = /(?<id>[\d]+)([ ]+)#(?<name>[^@]+)([ ]*)(?<participants>[@A-Za-z0-9'\- ]+)*/g;
- let events = {};
- for (let line of input) {
- if (line === 'Time for Code') {
- break;
- }
- if (line.match(pattern)) {
- let result = pattern.exec(line)
- let id = Number(result.groups.id);
- let name = result.groups.name.trim();
- let participants = [];
- if (result.groups.participants) {
- participants = [...new Set(result.groups.participants.split(' ').filter(el => el !== ''))];
- }
- if (!events[id]) {
- events[id] = { name, length: participants.length, participants }
- } else if (events[id].name === name) {
- let currentParticipants = events[id].participants;
- if (result.groups.participants) {
- participants = [...new Set(result.groups.participants.split(' ').filter(el => el !== '').concat(currentParticipants))];
- events[id] = { name, length: participants.length, participants }
- }
- }
- }
- }
- Object.entries(events)
- .sort((a, b) => b[1].length - a[1].length || a[1].name.localeCompare(b[1].name))
- .forEach(event => {
- console.log(`${event[1].name} - ${event[1].length}`)
- event[1].participants.sort((a, b) => a.localeCompare(b)).forEach(participant => console.log(`${participant}`));
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement