Advertisement
Guest User

Untitled

a guest
Mar 31st, 2019
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function keys(inputString) {
  2.     let regex = /[a-zA-Z0-9]{16,25}/g;
  3.     let areaInput = inputString[0].split('&');
  4.     let i = 0;
  5.     let ans = [];
  6.     for (let j = 0; j < areaInput.length; j++) {
  7.         let pattern = regex.exec(areaInput[j]);
  8.         if (pattern != null) {
  9.             let keyPassedTest = areaInput[j].split('');
  10.             let newKey = [];
  11.             let group = '';
  12.             keyPassedTest.forEach(simbol => {
  13.                 if (keyPassedTest.length === 16) {
  14.                     if (isNaN(simbol)) {
  15.                         group += simbol.toUpperCase();
  16.                     } else {
  17.                         group += Math.abs(Number(simbol) - 9);
  18.                     }
  19.                     i++;
  20.                     if (i === 4) {
  21.                         newKey.push(group);
  22.                         group = ''
  23.                         i = 0;
  24.                     }
  25.                 } else {
  26.                     if (isNaN(simbol)) {
  27.                         group += simbol.toUpperCase();
  28.                     } else {
  29.                         group += Math.abs(Number(simbol) - 9);
  30.                     }
  31.                     i++;
  32.                     if (i === 5) {
  33.                         newKey.push(group);
  34.                         group = ''
  35.                         i = 0;
  36.                     }
  37.                 }
  38.             });
  39.             ans.push(newKey.join('-'));
  40.         }
  41.     }
  42.     console.log(ans.join(', '));
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement