kstoyanov

09. Password Generator

Jul 17th, 2020
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(args) {
  2.   const strForPass = args[0].concat(args[1]);
  3.   const charsForNewPass = args[2].split('');
  4.   const arrOfChars = strForPass.toLowerCase().split('');
  5.  
  6.   const findVowels = (str) => str.match(/[aeiou]/ig);
  7.   let countVowels = 0;
  8.  
  9.   arrOfChars.forEach((ch, index) => {
  10.     if (findVowels(ch)) {
  11.       if (countVowels >= charsForNewPass.length) {
  12.         countVowels = 0;
  13.       }
  14.       if (charsForNewPass[countVowels] !== undefined) {
  15.         arrOfChars.splice(index, 1, charsForNewPass[countVowels].toUpperCase());
  16.       }
  17.  
  18.       countVowels += 1;
  19.     }
  20.   });
  21.  
  22.   console.log(`Your generated password is ${arrOfChars.reverse().join('')}`);
  23. }
Add Comment
Please, Sign In to add comment