Advertisement
megi_al

Emoji Detector

Mar 22nd, 2021 (edited)
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function emojiDetector([input]) {
  2.   let regex = /(\*\*|::)([A-Z][a-z]{2,})\1/g;
  3.   // или  /(::|\*\*)[A-Z]{1}[a-z]{2,}\1/g;
  4.   if (/[0-9]+/g.test(input)) {
  5.     let coolThreshold = input.match(/[0-9]/g);
  6.     coolN = 1;
  7.     for (let num of coolThreshold){
  8.       num = Number(num);
  9.       coolN *= num;
  10.     }
  11.     // let coolThreshold = input.match(/[0-9]+/g);.join('').split('').reduce((a, b) => {return a *= b; }, 1) || 0;
  12.     console.log(`Cool threshold: ${coolN}`);
  13.     // console.log(`Cool threshold:${coolThreshold}`);
  14.  
  15.     let matches = input.match(regex);
  16.     console.log(`${matches.length} emojis found in the text. The cool ones are:`);
  17.  
  18.     matches.forEach(x => {
  19.       let current = x.substring(2, x.length - 2);
  20.       let currentSum = current.split('').reduce((a, b) => a += b.charCodeAt(), 0);
  21.  
  22.       if (currentSum > coolN) {
  23.         console.log(x);
  24.  
  25.       }
  26.     })
  27.   }
  28. }
  29.  
  30. emojiDetector(
  31.   [
  32.     'In the Sofia Zoo there are 311 animals in total! ::Smiley:: This includes 3 **Tigers**, 1 ::Elephant:, 12 **Monk3ys**, a **Gorilla::, 5 ::fox:es: and 21 different types of :Snak::Es::. ::Mooning:: **Shy**'
  33.   ]
  34. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement