desito07

String Manipulator - Group 1

Jul 20th, 2020
269
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 "Translate":
  9.                 let 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 "Start":
  23.                 if(string.startsWith(firstArg)){
  24.                     console.log('True');                    
  25.                 } else {
  26.                     console.log('False');                    
  27.                 }
  28.                 break;
  29.             case "Lowercase":
  30.                 string = string.toLowerCase();
  31.                 console.log(string);                
  32.                 break;
  33.             case "FindIndex":
  34.                 let indexNeeded = string.lastIndexOf(firstArg);                  
  35.                 console.log(indexNeeded);                            
  36.                 break;
  37.             case "Remove":
  38.                 indexStart = Number(firstArg);  
  39.                 count = Number(secondArg);      
  40.                 let removed = string.substring(indexStart + count, string.length)
  41.                     .split(' ')
  42.                     .join(' ');
  43.                 console.log(removed);                
  44.                 break;
  45.             case "End":
  46.                 break;
  47.         }
  48.     }
  49. }
Add Comment
Please, Sign In to add comment