Advertisement
Guest User

02. Emoji Detector

a guest
Apr 9th, 2020
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function smile(input) {
  2.     const digits = input[0].match(/\d/g);
  3.     let threshold = BigInt;
  4.     if (digits) {
  5.         threshold = digits.map(Number).reduce((acc, curr) => acc * curr, 1);
  6.     } else {
  7.         threshold = 0
  8.     }
  9.     console.log(`Cool threshold: ${threshold}`);
  10.     const emojiPattern = /(::|\*\*)([A-Z][a-z]{2,})\1/g
  11.     const emojis = input[0].matchAll(emojiPattern);
  12.     if (emojis) {
  13.         const coolEmojis = [];
  14.         let count = 0;
  15.         for (const emj of emojis) {
  16.             // console.log(emj);
  17.             count++;
  18.             const emojiSum = emj[2].split('').reduce((sum, currEmj) => sum + currEmj.charCodeAt(0), 0);
  19.             // console.log(emojiSum);
  20.             if (emojiSum >= threshold) {
  21.                 coolEmojis.push(emj[0]);
  22.             }
  23.         }
  24.         let output = `${count} emojis found in the text. The cool ones are:`;
  25.         coolEmojis.forEach(coolEmj => output += `\n${coolEmj}`);
  26.         return output;
  27.     }
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement