Advertisement
ErolKZ

Untitled

Dec 1st, 2021
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1.  
  2. function solve(input) {
  3.  
  4. let conMess = input.shift();
  5.  
  6.  
  7. while (input[0] !== 'Reveal') {
  8.  
  9. let cur = input.shift().split(':|:');
  10.  
  11. let command = cur[0];
  12.  
  13. let subsOrIndex = cur[1];
  14.  
  15. let replacement = cur[2];
  16.  
  17. let before = '';
  18.  
  19. let after = '';
  20.  
  21.  
  22. if (command === 'InsertSpace') {
  23.  
  24. before = conMess.substring(0, subsOrIndex);
  25.  
  26. after = conMess.substring(subsOrIndex);
  27.  
  28. before += ' ';
  29.  
  30. conMess = before.concat(after);
  31.  
  32. console.log(conMess);
  33.  
  34. } else if (command === 'Reverse') {
  35.  
  36. if (conMess.includes(subsOrIndex)) {
  37.  
  38. conMess = conMess.replace(subsOrIndex, '');
  39.  
  40. subsOrIndex = subsOrIndex.split('').reverse().join('');
  41.  
  42. conMess += subsOrIndex;
  43.  
  44. console.log(conMess);
  45.  
  46. } else {
  47.  
  48. console.log('error');
  49.  
  50. }
  51.  
  52. } else if (command === 'ChangeAll') {
  53.  
  54. let regEx = RegExp(subsOrIndex, 'g');
  55.  
  56. // console.log(regEx);
  57.  
  58. conMess = conMess.replace(regEx, replacement);
  59.  
  60. console.log(conMess);
  61.  
  62. }
  63.  
  64.  
  65. }
  66.  
  67.  
  68.  
  69. console.log(`You have a new text message: ${conMess}`);
  70.  
  71. }
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement