Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function resetPswrd(input) {
- let str = input.shift().split("");
- let password = [];
- while (input[0] !== "Done") {
- let line = input.shift().split(" ");
- let command = line.shift();
- if (command === "TakeOdd") {
- for (let i = 0; i < str.length; i++) {
- if (i % 2 !== 0) {
- password.push(str[i]);
- }
- }
- password = password.join("");
- console.log(password);
- }
- if (command === "Cut") {
- let index = Number(line.shift());
- let length = Number(line.shift());
- let remove = password.substr(index, length);
- password = password.replace(remove, "");
- console.log(password);
- }
- if (command === "Substitute") {
- let substring = line.shift();
- let substitute = line.shift();
- if (password.includes(substring)) {
- password = password.split(substring).join(substitute);
- console.log(password);
- } else {
- console.log("Nothing to replace!");
- }
- }
- }
- console.log(`Your password is: ${password}`);
- }
- resetPswrd([
- "Siiceercaroetavm!:?:ahsott.:i:nstupmomceqr",
- "TakeOdd",
- "Cut 15 3",
- "Substitute :: -",
- "Substitute | ^",
- "Done",
- ]);
- resetPswrd([
- "up8rgoyg3r1atmlmpiunagt!-irs7!1fgulnnnqy",
- "TakeOdd",
- "Cut 18 2",
- "Substitute ! ***",
- "Substitute ? .!.",
- "Done",
- ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement