desito07

String Manipulator - Group 2

Jul 20th, 2020
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input){
  2.     let string = input.shift();
  3.  
  4.     for(let i = 0; i < input.length; i++){
  5.         let [ command, firstArg, secondArg] = input[i].split(' ');
  6.         // console.log(command);
  7.         switch(command){
  8.             case "Change":
  9.                 index = Number(firstArg);
  10.                 for(let i = 0; i < string.length; i++){
  11.                     string = string.replace(index, secondArg);
  12.                 }
  13.                 console.log(string);                
  14.                 break;
  15.             case "Includes":
  16.                 if(string.includes(firstArg)){
  17.                     console.log('True');                    
  18.                 } else {
  19.                     console.log('False');                    
  20.                 }
  21.                 break;
  22.             case "End":
  23.                 if(string.endsWith(firstArg)){
  24.                     console.log('True');                    
  25.                 } else {
  26.                     console.log('False');                    
  27.                 }
  28.                 break;
  29.             case "Uppercase":
  30.                 string = string.toUpperCase();
  31.                 console.log(string);                
  32.                 break;
  33.             case "FindIndex":
  34.                 let indexNeeded = string.indexOf(firstArg);
  35.                 console.log(indexNeeded);                
  36.                 break;
  37.             case "Cut":
  38.                 indexStart = Number(firstArg);
  39.                 length = Number(secondArg);                
  40.                 let cut = string.substring(indexStart, indexStart + length)
  41.                 .split(' ')
  42.                 .join(' ');    
  43.                 console.log(cut);                              
  44.                 break;
  45.             case "Done":
  46.                 break;
  47.         }
  48.     }
  49. }
Add Comment
Please, Sign In to add comment