Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.     let toSearchForDigits = input[0].slice().split('');
  3.     let coolTreshold = [];
  4.     // изчисляване на Threshold;
  5.     for (let i = 0; i < toSearchForDigits.length; i++) {
  6.         if (toSearchForDigits[i].charCodeAt(0) >= 48 && toSearchForDigits[i].charCodeAt(0) <= 57) {
  7.             let number = Number(toSearchForDigits[i]);
  8.             coolTreshold.push(number);
  9.         };
  10.     }
  11.     let sum = BigInt;
  12.     if (coolTreshold.length > 0) {
  13.         sum = 1;
  14.         for (let num of coolTreshold) {
  15.             sum *= num;
  16.         }
  17.     } else {
  18.         sum = 0;
  19.     }
  20.  
  21.     //RegEx проверка
  22.     let pattern = /(::|\*\*)([A-Z][a-z]{2,})\1/;
  23.     let inputArray = input[0].split(', ').join(' ').split(' ');
  24.     let totalMatches = 0;
  25.     let coolMatches = [];
  26.     for (let i = 0; i < inputArray.length; i++) {
  27.         let line = inputArray[i];
  28.         let match = pattern.exec(line);
  29.         if (match !== null) {
  30.             totalMatches++
  31.             let sumOfSymbols = 0;
  32.             let wordOnly = match[2];
  33.             for (let symbol of wordOnly) {
  34.                 sumOfSymbols += Number(symbol.charCodeAt(0));
  35.             }
  36.             if (sumOfSymbols >= sum) {
  37.                 coolMatches.push(match[0]);
  38.             }
  39.         }
  40.     }
  41.     console.log(`Cool threshold: ${sum}`);
  42.     console.log(`${totalMatches} emojis found in the text. The cool ones are:`);
  43.     for (let match of coolMatches) {
  44.         console.log(match);
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement