Advertisement
dilyana2001

Untitled

Jun 16th, 2021
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function passReset(arr) {
  2.     let password = arr.shift()
  3.     let result = ''
  4.     while (arr[0] != 'Done') {
  5.         let [command, ...args] = arr[0].split(' ')
  6.         if (command === 'TakeOdd') {
  7.             let passLength = password.length
  8.             for (let i = 1; i < passLength; i += 2) {
  9.                 result += password[i]
  10.             }
  11.             console.log(result)
  12.         } else if (command === 'Cut') {
  13.             let [index, length] = args
  14.             index = Number(index)
  15.             length = Number(length)
  16.             let firstPart = result.substring(0, index)
  17.             let secondPart = result.substring(index + length)
  18.             result = firstPart + secondPart
  19.             console.log(result)
  20.         } else if (command === 'Substitute') {
  21.             let [substring, substitute] = args
  22.             if (result.includes(substring)) {
  23.                 result = result.replace(new RegExp(`${substring}`, 'g'), substitute)
  24.                 console.log(result)
  25.             } else {
  26.                 console.log(`Nothing to replace!`);
  27.             }
  28.         }
  29.         arr.shift()
  30.     }
  31.     if (arr[0] === 'Done') {
  32.         console.log(`Your password is: ${result}`);
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement