Advertisement
kstoyanov

01. Email Validator js exam

Aug 13th, 2020
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(args) {
  2.   let email = args.shift();
  3.   let lineInput = args.shift();
  4.  
  5.   while (lineInput !== 'Complete') {
  6.     const [command, arg1] = lineInput.split(' ');
  7.  
  8.     switch (command) {
  9.       case 'Make':
  10.  
  11.         if (arg1 === 'Upper') {
  12.           email = email.toUpperCase();
  13.           console.log(email);
  14.         } else if (arg1 === 'Lower') {
  15.           email = email.toLowerCase();
  16.           console.log(email);
  17.         }
  18.  
  19.  
  20.         break;
  21.       case 'GetDomain':
  22.         const srt = email.slice(0, email.length - Number(arg1));
  23.         const lastCount = email.slice(srt.length - 1 + 1);
  24.         console.log(lastCount);
  25.         break;
  26.  
  27.       case 'GetUsername':
  28.  
  29.         if (email.includes('@')) {
  30.           const takeIndexStr = email.indexOf('@');
  31.           const takeUserName = email.slice(0, takeIndexStr);
  32.           console.log(takeUserName);
  33.         } else {
  34.           console.log(`The email ${email} doesn't contain the @ symbol.`);
  35.        }
  36.  
  37.        break;
  38.  
  39.      case 'Replace':
  40.        while (email.includes(arg1)) {
  41.          email = email.replace(arg1, '-');
  42.        }
  43.        console.log(email);
  44.        break;
  45.  
  46.      case 'Encrypt':
  47.        const toAcii = email.split('')
  48.          .map((chr) => chr.charCodeAt())
  49.          .join(' ');
  50.  
  51.        console.log(toAcii);
  52.        break;
  53.  
  54.  
  55.      default:
  56.        break;
  57.    }
  58.  
  59.  
  60.    lineInput = args.shift();
  61.  }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement