Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.   let pattern = /(?<tag>(\*){2}|(\:){2})(?<onlyWord>[A-Z][a-z]{2,})\1/gi;
  3.   let threshold = /\d+/g;
  4.   let emojis = [];
  5.   let cool = 1;
  6.   let sum = 0;
  7.   let string = input[0].split(" ");
  8.   let coolEmojis = [];
  9.   for (const iterator of string) {
  10.     let match = iterator.match(pattern);
  11.     let thresholdMatches = threshold.exec(iterator);
  12.     if (match != null) {
  13.       emojis.push(match[0]);
  14.     }
  15.     if (thresholdMatches != null) {
  16.       let numbers = thresholdMatches.toString().split("");
  17.       for (let i = 0; i < numbers.length; i++) cool *= Number(numbers[i]);
  18.     }
  19.   }
  20.   console.log(`Cool threshold: ${cool}`);
  21.   for (const el of emojis) {
  22.     let string = el.slice(2, el.length - 2);
  23.     for (let i = 0; i < string.length; i++) {
  24.       sum += string.charCodeAt(i);
  25.     }
  26.     if (sum > cool) {
  27.       coolEmojis.push(el);
  28.       sum = 0;
  29.     }
  30.   }
  31.   console.log(
  32.     `${
  33.       emojis.length
  34.     } emojis found in the text. The cool once are: \n${coolEmojis.join("\n")}`
  35.   );
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement