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