Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve (...params) {
- let arr = params[0];
- let msg = arr.shift();
- for (let i in arr) {
- let temp = arr[i].toString().split("|");
- if (temp[0] == "ChangeAll") {
- let change = temp[1];
- let to = temp[2];
- msg = msg.toString().replace(new RegExp(`${change}`, "g"), `${to}`);
- } else if (temp[0] == "Insert") {
- let index = temp[1];
- let character = temp[2];
- if (index > msg.length) {
- index = msg.length;
- }
- msg = msg.toString().substr(0, index) + character + msg.toString().substr(index);
- } else if (temp[0] == "Move") {
- let toIndexMove = temp[1];
- if (toIndexMove > msg.length) {
- continue;
- }
- msg = msg.toString().substr(toIndexMove) + msg.toString().substr(0, toIndexMove);
- } else if (temp[0] == "Decode") {
- console.log(`The decrypted message is: ${msg}`);
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement