Advertisement
ErolKZ

Untitled

Dec 2nd, 2021
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1.  
  2. function solve(input) {
  3.  
  4.  
  5. let str = input.shift();
  6.  
  7. let str2 = '';
  8.  
  9.  
  10. while (input[0] !== 'Done') {
  11.  
  12. let cur = input.shift().split(' ');
  13.  
  14. let command = cur[0];
  15.  
  16. // console.log(cur);
  17.  
  18. if (command === 'TakeOdd') {
  19.  
  20.  
  21. for (let i = 0; i < str.length; i++) {
  22.  
  23. if (i % 2 !== 0) {
  24.  
  25. str2 += str[i];
  26.  
  27. }
  28.  
  29. }
  30.  
  31. console.log(str2);
  32.  
  33.  
  34. } else if (command === 'Cut') {
  35.  
  36. let subStr = str2.split('').splice(cur[1], cur[2]);
  37.  
  38. str2 = str2.replace(subStr.join(''), '');
  39.  
  40. console.log(str2);
  41.  
  42.  
  43. } else if (command === 'Substitute') {
  44.  
  45. if (str2.includes(cur[1])) {
  46.  
  47. let subStr = RegExp(cur[1], 'g');
  48.  
  49. str2 = str2.replace(subStr, cur[2]);
  50.  
  51. console.log(str2);
  52.  
  53. } else {
  54.  
  55. console.log(`Nothing to replace!`);
  56.  
  57. }
  58.  
  59. }
  60.  
  61.  
  62.  
  63.  
  64.  
  65. }
  66.  
  67.  
  68.  
  69. console.log(`Your password is: ${str2}`);
  70.  
  71.  
  72. }
  73.  
  74.  
  75.  
  76.  
  77. solve(
  78.  
  79. ["Siiceercaroetavm!:?:ahsott.:i:nstupmomceqr",
  80.  
  81. "TakeOdd",
  82.  
  83. "Cut 15 3",
  84.  
  85. "Substitute :: -",
  86.  
  87. "Substitute | ^",
  88.  
  89. "Done"]
  90.  
  91. );
  92.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement