Todorov_Stanimir

06. Wall Builder Text Proces.and Reg.Express.-More Exercises

Jun 4th, 2019
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function wallBuilder(input) {
  2.     let base = [];
  3.     let middle = [];
  4.     let top = [];
  5.     let separator = input.length / 3;
  6.     for (let index in input) {
  7.         if ((Number(index) + 1) / separator <= 1) {
  8.             base.push(input[index]);
  9.         } else if ((Number(index) + 1) / separator <= 2) {
  10.             middle.push(input[index]);
  11.         } else if ((Number(index) + 1) / separator <= 3) {
  12.             top.push(input[index]);
  13.         }
  14.     }
  15.     checkerBase(base);
  16.     checkerMiddle(middle)
  17.     checkerTop(top)
  18.  
  19.     function checkerBase(base) {
  20.         let pattern = /\b[A-Z]{1,}[0-9]{4,}?([A-Z]{1,}[0-9]{4,})*\b/g;
  21.         base.forEach(element => {
  22.             if (element.match(pattern)) {
  23.                 console.log('SOLID BASE!');
  24.             } else {
  25.                 console.log('WEAK BASE!');
  26.             }
  27.         });
  28.     }
  29.  
  30.     function checkerMiddle(middle) {
  31.         middle.forEach(element => {
  32.             let isSolidMiddle = true;
  33.             for (let index = 0; index < element.length; index++) {
  34.                 if ((0 <= index && index <= 2) &&
  35.                     ((element[index] < 'A' || ('Z' < element[index] && element[index] < 'a') || 'z' < element[index]))) {
  36.                     isSolidMiddle = false;
  37.                     break;
  38.                 } else if ((index > 2 && index < element.length - 2) &&
  39.                     (element[index] <= '"' || ('&' <= element[index] && element[index] <= '?') ||
  40.                         ('[' <= element[index] && element[index] <= '`') || '{' <= element[index])) {
  41.                     isSolidMiddle = false;
  42.                     console.log(element.charCodeAt(index));
  43.                     console.log(index);
  44.                     break;
  45.                 } else if ((index === element.length - 1) &&
  46.                     (element[index] <= '"' || ('%' <= element[index] && element[index] !== '@'))) {
  47.                     isSolidMiddle = false;
  48.                     break;
  49.                 }
  50.             }
  51.             if (isSolidMiddle) {
  52.                 console.log('SOLID MIDDLE!');
  53.             } else {
  54.                 console.log('WEAK MIDDLE!');
  55.             }
  56.         });
  57.     }
  58.  
  59.     function checkerTop(top) {
  60.         let pattern = /\b0+([a-z]{0,5}[0])+\1+[a-z]{1,5}\b/g;
  61.         top.forEach(element => {
  62.             if (element.match(pattern)) {
  63.                 console.log('SOLID TOP!');
  64.             } else {
  65.                 console.log('WEAK TOP!');
  66.             }
  67.         });
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment