Liliana797979

password reset - final exam - fundamentals

Aug 6th, 2021
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.      
  3. function passwordReset(input) {
  4.     let operations = {
  5.         TakeOdd,
  6.         Cut,
  7.         Substitute
  8.     }
  9.  
  10.     let rawPassword = input.shift()
  11.  
  12.     while(input[0] != 'Done') {
  13.         let tokens = input.shift().split(' ')
  14.         let command = operations[tokens[0]]
  15.         rawPassword = command(rawPassword,tokens[1],tokens[2])
  16.  
  17.     }
  18.  
  19.     console.log(`Your password is: ${rawPassword}`);
  20.  
  21.     function TakeOdd(text) {
  22.         let result = '';
  23.         for(let i = 1; i < text.length; i+= 2) {
  24.             if(text[i] % 2 != 0) {
  25.                 result += text[i]
  26.             }
  27.         }
  28.         console.log(result);
  29.         return result
  30.     }
  31.  
  32.  
  33.     function Cut(text, start, count) {
  34.         start = Number(start)
  35.         count = Number(count)
  36.         let word = text.substring(start, start + count)
  37.         let result = text.replace(word, '')
  38.         console.log(result);
  39.         return result
  40.     }
  41.  
  42.  
  43.     function Substitute(text, match, word) {
  44.         let result  = text.split(match).join(word)
  45.         if(result === text) {
  46.             console.log('Nothing to replace!');
  47.         } else {
  48.             console.log(result);
  49.         }
  50.         return result
  51.  
  52.     }
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment