Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let favoriteGenres = input.shift().split(' | ');
- let line = input.shift();
- while (line != 'Stop!') {
- let [command, genre, newGenre] = line.split(' ');
- switch (command) {
- case 'Join':
- if (favoriteGenres.includes(genre) == false) {
- favoriteGenres.push(genre);
- }
- break;
- case 'Drop':
- if (favoriteGenres.includes(genre) == true) {
- let index = favoriteGenres.indexOf(genre);
- favoriteGenres.splice(index, 1);
- }
- break;
- case 'Replace':
- if (favoriteGenres.includes(genre) == true) {
- let index = favoriteGenres.indexOf(genre);
- favoriteGenres[index] = newGenre;
- }
- break;
- default:
- break;
- }
- line = input.shift();
- }
- console.log(favoriteGenres.join(' '));
- }
Advertisement
Add Comment
Please, Sign In to add comment