Advertisement
Caruzov

Untitled

Jan 25th, 2022
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. function solve (...params) {
  2.  
  3. let arr = params[0];
  4. let msg = arr.shift();
  5.  
  6. for (let i in arr) {
  7. let temp = arr[i].toString().split("|");
  8. if (temp[0] == "ChangeAll") {
  9. let change = temp[1];
  10. let to = temp[2];
  11. msg = msg.toString().replace(new RegExp(`${change}`, "g"), `${to}`);
  12. } else if (temp[0] == "Insert") {
  13. let index = temp[1];
  14. let character = temp[2];
  15. if (index > msg.length) {
  16. index = msg.length;
  17. }
  18. msg = msg.toString().substr(0, index) + character + msg.toString().substr(index);
  19. } else if (temp[0] == "Move") {
  20. let toIndexMove = temp[1];
  21. if (toIndexMove > msg.length) {
  22. continue;
  23. }
  24. msg = msg.toString().substr(toIndexMove) + msg.toString().substr(0, toIndexMove);
  25. } else if (temp[0] == "Decode") {
  26. console.log(`The decrypted message is: ${msg}`);
  27. break;
  28. }
  29. }
  30.  
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement