Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function passwordReset(input) {
- let password = input.shift();
- let commandLine = input.shift();
- let newPass = "";
- while (commandLine !== "Done") {
- if (commandLine.includes("TakeOdd")) {
- for (let i = 0; i < password.length; i++) {
- if (i % 2 === 1) {
- newPass += password[i];
- }
- }
- console.log(newPass);
- } else if (commandLine.includes("Substitute")) {
- let [command, substring, substitute] = commandLine.split(' ');
- if (newPass.includes(substring)) {
- while (newPass.includes(substring)) {
- newPass = newPass.replace(substring, substitute);
- }
- console.log(newPass);
- } else {
- console.log(`Nothing to replace!`);
- }
- } else if (commandLine.includes("Cut")) {
- let [command, index, length] = commandLine.split(' ');
- index = Number(index);
- length = Number(length);
- let cut = newPass.substr(index, length);
- newPass = newPass.replace(cut, '');
- console.log(newPass);
- }
- commandLine = input.shift();
- }
- console.log(`Your password is: ${newPass}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement