Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function passWordResset(password) {
- let elements = password.slice(1);
- let pwd = password.shift();
- for (let i = 0; i < elements.length; i++) {
- let currentElement = elements[i].split(' ');
- let command = currentElement[0];
- if (command === 'TakeOdd') {
- pwd = pwd.split('').reduce((pwd, char, idx) => {
- if(idx % 2 === 1) pwd += char;
- return pwd;
- }, '');
- console.log(pwd);
- } else if (command === 'Cut') {
- let index = Number(currentElement[1]);
- let length = Number(currentElement[2]);
- pwd = pwd.substr(0, index) + pwd.substring(index + length);
- console.log(pwd);
- } else if (command === 'Substitute') {
- let currentSymbol = currentElement[1];
- let replace = currentElement[2];
- let isFound = pwd.indexOf(currentSymbol);
- if (isFound !== -1) {
- pwd = pwd.replace(new RegExp(currentSymbol, 'g'), replace);
- console.log(pwd);
- } else {
- console.log(`Nothing to replace!`);
- }
- } else if (command === 'Done') {
- console.log(`Your password is: ${pwd}`);
- break;
- }
- }
- }
Add Comment
Please, Sign In to add comment