Advertisement
Guest User

Untitled

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