Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let result = input.shift();
- while (input[0] != "Decode") {
- let tokens = input.shift().split("|");
- let command = tokens[0];
- if (command == "Move") {
- let index = Number(tokens[1]);
- let left = result.substring(0, index);
- let right = result.substring(index);
- result = right + left;
- // console.log(result);
- } else if (command == "Insert") {
- let index = Number(tokens[1]);
- let left = result.substring(0, index);
- let right = result.substring(index);
- let value = tokens[2];
- result = left + value + right;
- } else if (command == "ChangeAll") {
- result = result.split(tokens[1]).join(tokens[2]);
- }
- }
- console.log(`The decrypted message is: ` + result);
- }
- solve([
- 'zzHe',
- 'ChangeAll|z|l',
- 'Insert|2|o',
- 'Move|3',
- 'Decode'
- ]
- );
Advertisement
Add Comment
Please, Sign In to add comment