Advertisement
teofarov13

Untitled

Apr 2nd, 2023
550
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function stringManipulator(data) {
  2.     let msg = data.shift();
  3.     let commands = data.shift();
  4.     while (commands !== 'End') {
  5.         let command = commands.split(" ")
  6.  
  7.         switch (command[0]) {
  8.             case 'Translate':
  9.                 let forReplace = command[1];
  10.                 let replaced = command[2];
  11.                 while (msg.includes(forReplace)) {
  12.  
  13.                     msg = msg.replace(forReplace, replaced)
  14.                 }
  15.                 console.log(msg);
  16.                 break;
  17.             case 'Includes':
  18.                 let word = command[1];
  19.                 if (msg.includes(word)) {
  20.                     console.log('True');
  21.                 } else {
  22.                     console.log('False');
  23.                 }
  24.                 break;
  25.             case 'Start':
  26.                 let start = command[1];
  27.                 if (msg.startsWith(start)) {
  28.                     console.log('True');
  29.                 } else {
  30.                     console.log('False');
  31.                 }
  32.                 break;
  33.             case 'Lowercase':
  34.                 msg = msg.toLowerCase()
  35.                 console.log(msg);
  36.                 break;
  37.             case 'FindIndex':
  38.                 let find = command[1];
  39.                 let last = msg.lastIndexOf(find);
  40.                 console.log(last);
  41.                 break;
  42.             case 'Remove':
  43.                 let begin = +(command[1]);
  44.                 let end = +(command[2]);
  45.                 msg = msg.substring(0, begin) + msg.substring(begin + end)
  46.                 console.log(msg);
  47.                 break;
  48.         }
  49.         commands = data.shift()
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement