Guest User

Untitled

a guest
Aug 1st, 2020
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. function solve(input) {
  2.  
  3. let activationKey = input.splice(0,1).toString()
  4. let commands = input.shift();
  5.  
  6. while(commands !== 'Generate'){
  7.  
  8. let separatedCommands = commands.split('>>>');
  9. if(separatedCommands[0] === 'Slice'){
  10. let newStr = ''
  11. let startIndex = Number(separatedCommands[1]);
  12. let endIndex = Number(separatedCommands[2]);
  13. if((startIndex >= 0 && endIndex >= 0) && (startIndex < activationKey.length && activationKey.length > endIndex)){
  14. let slicedActivationKey = activationKey.substring(startIndex,endIndex);
  15. newStr = activationKey.replace(slicedActivationKey,'');
  16. activationKey = newStr;
  17. console.log(activationKey);
  18. }
  19. }else if(separatedCommands[0] === 'Flip'){
  20. if(separatedCommands [1] === 'Upper'){
  21. let startIndex = Number(separatedCommands[2]);
  22. let endIndex = Number(separatedCommands[3]);
  23. let neededChar = activationKey.substring(startIndex,endIndex);
  24. let changedneededChar = neededChar.toUpperCase();
  25. let replaced = activationKey.replace(neededChar,changedneededChar)
  26. activationKey = replaced;
  27. console.log(activationKey);
  28. }else if(separatedCommands[1] === 'Lower'){
  29. let startIndex = Number(separatedCommands[2]);
  30. let endIndex = Number(separatedCommands[3]);
  31. let neededChar = activationKey.substring(startIndex,endIndex);
  32. let changedneededChar = neededChar.toLowerCase();
  33. let replaced = activationKey.replace(neededChar,changedneededChar);
  34. activationKey = replaced;
  35. console.log(activationKey);
  36. }
  37. }else if(separatedCommands[0] === 'Contains'){
  38. let neededSubstringg = separatedCommands[1];
  39. if(activationKey.includes(neededSubstringg)){
  40. console.log(`${activationKey} contains ${neededSubstringg}.`);
  41. }else{
  42. console.log(`Substring not found!`);
  43. }
  44. }
  45. commands = input.shift()
  46. }
  47.  
  48. console.log(`Your activation key is: ${newStr}`);
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment