Advertisement
ErolKZ

Untitled

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