Todorov_Stanimir

03. Post Office Fundament Retake Exam - 27.08.2018 II part

Jun 23rd, 2019
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function postOffice(input) {
  2.     let [word1, word2, word3] = String(input.shift()).split('|');
  3.     let wordFirst = ''
  4.     let patternFirstPart = /([#\$%\*&])([A-Z]+)\1/g;
  5.     wordFirst = word1.match(patternFirstPart)[0].substring(1, word1.match(patternFirstPart)[0].length - 1);
  6.    
  7.     wordFirst = wordFirst.split('');
  8.     let wordSecond = word2.match(/[\d]{2}:[\d]{2}/g);
  9.     let lengthWord1 = [];
  10.     for (let index in wordFirst) {
  11.         for (let i = 0; i < wordSecond.length; i++) {
  12.             let [charCode, dalzhina] = String(wordSecond[i]).split(':');
  13.             if (wordFirst[index] === String.fromCharCode(charCode)) {
  14.                 if (1 <= Number(dalzhina) && Number(dalzhina) <= 20) {
  15.                     lengthWord1.push(Number(dalzhina));
  16.                     break;
  17.                 }
  18.             }
  19.         }
  20.     }
  21.     let wordThird = word3.split(' ');
  22.     for (let y = 0; y < wordFirst.length; y++) {
  23.         for (let i = 0; i < wordThird.length; i++) {
  24.             if (String(wordThird[i])[0] === wordFirst[y] && Number(wordThird[i].length) === Number(lengthWord1[y])+1) {
  25.                 console.log(wordThird[i]);
  26.                
  27.             }
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment