desito07

Username

Jul 19th, 2020 (edited)
489
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input){
  2.     let username = 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 "Case":
  9.                 if(firstArg === "lower"){
  10.                    username = username.toLowerCase();  
  11.                    console.log(username);                  
  12.                 } else if(firstArg === "upper"){
  13.                     username = username.toUpperCase();
  14.                     console.log(username);                    
  15.                 }
  16.                 break;
  17.             case "Reverse":
  18.                 indexStart = Number(firstArg);
  19.                 indexEnd = Number(secondArg);                
  20.                 if(indexStart>= 0 && indexStart < username.length && indexEnd >= 0 && indexEnd < username.length){
  21.                     let str = username.substring(indexStart, indexEnd + 1)
  22.                     .split('')
  23.                     .reverse()
  24.                     .join('');
  25.                    console.log(str);                  
  26.                 }                
  27.                 break;
  28.             case "Cut":                
  29.                 if(username.includes(firstArg)){
  30.                    username = username.replace(firstArg, '');
  31.                         console.log(username);                      
  32.                 } else {
  33.                     console.log(`The word ${username.toLowerCase()} doesn't contain ${firstArg}.`);
  34.                }              
  35.                break;
  36.            case "Replace":
  37.                for(let i = 0; i < username.length; i++){
  38.                    if(username.includes(firstArg)){
  39.                    username = username.replace(firstArg, '*');
  40.                    }                  
  41.                }
  42.                console.log(username);
  43.                break;
  44.            case "Check":
  45.                if(username.includes(firstArg)){
  46.                    console.log("Valid");                    
  47.                } else {
  48.                    console.log(`Your username must contain ${firstArg}.`);
  49.                    
  50.                }
  51.                break;
  52.            default:              
  53.                break;
  54.        }
  55.        
  56.    }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment