Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let str = input.shift();
- let str2 = '';
- while (input[0] !== 'Done') {
- let cur = input.shift().split(' ');
- let command = cur[0];
- // console.log(cur);
- if (command === 'TakeOdd') {
- for (let i = 0; i < str.length; i++) {
- if (i % 2 !== 0) {
- str2 += str[i];
- }
- }
- console.log(str2);
- } else if (command === 'Cut') {
- let subStr = str2.split('').splice(cur[1], cur[2]);
- str2 = str2.replace(subStr.join(''), '');
- console.log(str2);
- } else if (command === 'Substitute') {
- if (str2.includes(cur[1])) {
- let subStr = RegExp(cur[1], 'g');
- str2 = str2.replace(subStr, cur[2]);
- console.log(str2);
- } else {
- console.log(`Nothing to replace!`);
- }
- }
- }
- console.log(`Your password is: ${str2}`);
- }
- solve(
- ["Siiceercaroetavm!:?:ahsott.:i:nstupmomceqr",
- "TakeOdd",
- "Cut 15 3",
- "Substitute :: -",
- "Substitute | ^",
- "Done"]
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement