Advertisement
didkoslawow

Untitled

Mar 26th, 2023
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function emojiDecoder(input) {
  2.    const thresholdPattern = /[\d+]/gm;
  3.    let threshold = 1;
  4.    let thresholdMatch;
  5.  
  6.    while ((thresholdMatch = thresholdPattern.exec(input))) {
  7.      threshold *= Number(thresholdMatch[0]);
  8.    }
  9.  
  10.    const emojiPattern = /(:{2}|\*{2})([A-Z][a-z]{2,})(\1)/gm;
  11.    const emojies = [];
  12.  
  13.    let validEmojies;
  14.  
  15.    while ((validEmojies = emojiPattern.exec(input))) {
  16.      emojies.push(validEmojies[0]);
  17.    }
  18.  
  19.    console.log(`Cool threshold: ${threshold}`);
  20.    console.log(`${emojies.length} emojis found in the text. The cool ones are:`);
  21.  
  22.    emojies.filter((emoji) => isCoolEmoji(emoji)).forEach(=> {
  23.      console.log(e);
  24.    });
  25.      
  26.  
  27.    function isCoolEmoji(emoji) {
  28.      const coolness = emoji.split('').reduce((acc, ch) => {
  29.        if (ch !== ':' && ch !== '*') {
  30.          acc += ch.charCodeAt();
  31.        }
  32.        return acc;
  33.      }, 0);
  34.  
  35.      if (coolness > threshold) {
  36.          return true;
  37.      }
  38.  
  39.      return false;
  40.    }
  41.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement