Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function theImitacionGame(input) {
- let message = input.shift();
- while (input[0] != "Decode") {
- let tokens = input.shift().split('|');
- let command = tokens[0];
- if (command == "Move") {
- let index = Number(tokens[1]);
- message = message.substring(index) + message.slice(0, index);
- } else if (command == "Insert") {
- let index = Number(tokens[1]);
- let value = tokens[2];
- message = message.slice(0, index) + value + message.slice(index);
- } else if (command == "ChangeAll") {
- let oldStr = tokens[1];
- let newStr = tokens[2];
- while(message.includes(oldStr)){
- message = message.replace(oldStr, newStr);
- }
- }
- }
- console.log(`The decrypted message is: ${message}`);
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement