Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function passReset(arr) {
- let password = arr.shift()
- let result = ''
- while (arr[0] != 'Done') {
- let [command, ...args] = arr[0].split(' ')
- if (command === 'TakeOdd') {
- let passLength = password.length
- for (let i = 1; i < passLength; i += 2) {
- result += password[i]
- }
- console.log(result)
- } else if (command === 'Cut') {
- let [index, length] = args
- index = Number(index)
- length = Number(length)
- let firstPart = result.substring(0, index)
- let secondPart = result.substring(index + length)
- result = firstPart + secondPart
- console.log(result)
- } else if (command === 'Substitute') {
- let [substring, substitute] = args
- if (result.includes(substring)) {
- result = result.replace(new RegExp(`${substring}`, 'g'), substitute)
- console.log(result)
- } else {
- console.log(`Nothing to replace!`);
- }
- }
- arr.shift()
- }
- if (arr[0] === 'Done') {
- console.log(`Your password is: ${result}`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement