Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let quests = input.shift().split(', ');
- let startCheck = 0;
- for (let i = 0; i < input.length; i++) {
- let command = input[i].split(' - ');
- if (command[0] === 'Start') {
- for(let b = 0; b< quests.length; b++){
- if (command[1] === quests[b]){
- startCheck = 0;
- continue;
- }else{
- startCheck = 1;
- }
- }
- if(startCheck === 1){
- quests.push(command[1])
- }
- }else if(command[0] === 'Complete'){
- let check = quests.indexOf(command[1])
- if(check !== -1){
- quests.splice(check, 1)
- }
- }else if(command[0] === 'Side Quest'){
- let commandTwo = command[1].split(`:`)
- let sideQuestCheck = quests.indexOf(commandTwo[0]);
- if(sideQuestCheck !== -1){
- let sideQuestSecondCheck = quests.indexOf(commandTwo[1])
- if(sideQuestSecondCheck === -1){
- quests.splice(sideQuestCheck+1,0,commandTwo[1])
- }
- }
- }else{
- let renewCheck = quests.indexOf(command[1])
- if(renewCheck !== -1){
- let p = quests.splice(renewCheck, 1)
- quests.push(p[0])
- }
- }
- }
- console.log(quests.join(`, `))
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement