Advertisement
bebo231312312321

Untitled

Mar 24th, 2023
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function worldTour(input){
  2.     let stops = input.shift()
  3.     function addStop(a,c){
  4. if (stops[a]!== undefined)
  5.     stops = stops.substring(0,a) + c + stops.substring(a)
  6.     }
  7.     function remove(a,c){
  8. if(stops[a]!== undefined && stops[c]!== undefined)
  9.     stops = stops.slice(0,a) + stops.slice(c+1)
  10.     }
  11.     function switchS(a,c){
  12. if(stops.indexOf(a)!== -1){
  13.     let regex = new RegExp(a,"g")
  14.     stops = stops.replace(regex,c)
  15. }
  16.     }
  17.     let travels =  input.splice(0,input.indexOf("Travel")).forEach(x => {
  18.         let [comand,a,c] = x.split(":").map(x=>(isNaN(x)?x:Number(x)))
  19.      switch(comand){
  20.         case "Add Stop":{addStop(a,c)}break;
  21.         case "Remove Stop":{remove(a,c)}break;
  22.         case "Switch":{switchS(a,c)}break;
  23.      }
  24.         console.log(stops)
  25.     });
  26.     console.log(`Ready for world tour! Planned stops: ${stops}`)
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement