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') {
- let strLength = str.length;
- if (str2.length > 0) {
- str = str2;
- str2 = '';
- strLength = str.length;
- }
- for (let i = 0; i < strLength; i++) {
- if (i % 2 !== 0) {
- str2 += str[i];
- }
- }
- console.log(str2);
- } else if (command === 'Cut') {
- if (str2 === '') {
- str2 = str;
- }
- let subStr = str2.substring(cur[1]);
- let subStr2 = subStr.substring(cur[2]);
- str2 = str2.substring(0, cur[1]);
- str2 += subStr2;
- console.log(str2);
- } else if (command === 'Substitute') {
- if (str2 === '') {
- str2 = str;
- }
- if (str2.includes(cur[1])) {
- while (str2.includes(cur[1])) {
- str2 = str2.replace(cur[1], cur[2]);
- }
- console.log(str2);
- } else {
- console.log(`Nothing to replace!`);
- }
- }
- }
- console.log(`Your password is: ${str2}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement