Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function softUniKaraoke(input) {
- let participants = input.shift().split(", "),
- songs = input.shift().split(", "),
- info = {};
- while (true) {
- let command = input.shift();
- if (command === "dawn") {
- break;
- }
- let [participant, song, award] = command.split(", ");
- if (participants.includes(participant) && songs.includes(song)) {
- if (!info.hasOwnProperty(participant)) {
- info[participant] = new Set();
- }
- info[participant].add(award);
- }
- }
- info = Object.fromEntries(
- Object.entries(info).sort((a, b) => b[1].size - a[1].size)
- );
- if (Object.keys(info).length > 0) {
- for (let key in info) {
- console.log(`${key}: ${info[key].size} awards`);
- for (let value of Array.from(info[key]).sort()) {
- console.log(`--${value}`);
- }
- }
- } else {
- console.log("No awards");
- }
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement