Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input){
- let string = input.shift();
- for(let i = 0; i < input.length; i++){
- let [ command, firstArg, secondArg] = input[i].split(' ');
- // console.log(command);
- switch(command){
- case "Translate":
- let index = Number(firstArg);
- for(let i = 0; i < string.length; i++){
- string = string.replace(index, secondArg);
- }
- console.log(string);
- break;
- case "Includes":
- if(string.includes(firstArg)){
- console.log('True');
- } else {
- console.log('False');
- }
- break;
- case "Start":
- if(string.startsWith(firstArg)){
- console.log('True');
- } else {
- console.log('False');
- }
- break;
- case "Lowercase":
- string = string.toLowerCase();
- console.log(string);
- break;
- case "FindIndex":
- let indexNeeded = string.lastIndexOf(firstArg);
- console.log(indexNeeded);
- break;
- case "Remove":
- indexStart = Number(firstArg);
- count = Number(secondArg);
- let removed = string.substring(indexStart + count, string.length)
- .split(' ')
- .join(' ');
- console.log(removed);
- break;
- case "End":
- break;
- }
- }
- }
Add Comment
Please, Sign In to add comment