Advertisement
ErolKZ

Untitled

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