Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(args) {
- let inputPassword = args.shift();
- const lines = args.slice(0, args.indexOf('Done'));
- lines.forEach((line) => {
- const [command, value, value2] = line.split(' ');
- switch (command) {
- case 'TakeOdd':
- let tempStr = '';
- for (let i = 0; i < inputPassword.length; i++) {
- if (i % 2 !== 0) {
- tempStr += inputPassword[i];
- }
- }
- inputPassword = tempStr;
- console.log(inputPassword);
- break;
- case 'Cut':
- const index = Number(value);
- const length = Number(value2);
- const arr = Array.from(inputPassword).splice(index, length).join('');
- inputPassword = inputPassword.replace(arr, '');
- console.log(inputPassword);
- break;
- case 'Substitute':
- const substring = value;
- const substitute = value2;
- if (!inputPassword.includes(substring)) {
- console.log('Nothing to replace!');
- } else {
- while (inputPassword.includes(substring)) {
- inputPassword = inputPassword.replace(substring, substitute);
- }
- console.log(inputPassword);
- }
- }
- });
- console.log(`Your password is: ${inputPassword}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement