Advertisement
ErolKZ

Untitled

Dec 2nd, 2021
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. function solve(input) {
  2.  
  3. let str = input.shift();
  4.  
  5. let str2 = '';
  6.  
  7. while (input[0] !== 'Done') {
  8.  
  9. let cur = input.shift().split(' ');
  10.  
  11. let command = cur[0];
  12.  
  13. // console.log(cur);
  14.  
  15. if (command === 'TakeOdd') {
  16.  
  17. for (let i = 0; i < str.length; i++) {
  18.  
  19. if (i % 2 !== 0) {
  20.  
  21. str2 += str[i];
  22.  
  23. }
  24.  
  25. }
  26.  
  27. console.log(str2);
  28.  
  29. } else if (command === 'Cut') {
  30.  
  31. let subStr = str2.split('').splice(cur[1], cur[2]);
  32.  
  33. str2 = str2.replace(subStr.join(''), '');
  34.  
  35. console.log(str2);
  36.  
  37. } else if (command === 'Substitute') {
  38.  
  39. if (str2.includes(cur[1])) {
  40.  
  41. while (str2.includes(cur[1])) {
  42.  
  43. str2 = str2.replace(cur[1], cur[2]);
  44.  
  45. }
  46.  
  47. console.log(str2);
  48.  
  49. } else {
  50.  
  51. console.log(`Nothing to replace!`);
  52.  
  53. }
  54.  
  55. }
  56.  
  57.  
  58. }
  59.  
  60. console.log(`Your password is: ${str2}`);
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement