Advertisement
Malinov

Untitled

Aug 19th, 2021
1,621
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function emojiDetector([input]) {
  2.  
  3.     let emojiPattern = /(::|\*\*)(?<emoji>[A-Z][a-z]{2,})\1/g;
  4.     let numPattern = /\d/gm;
  5.  
  6.     let coolTreshhold = input.match(numPattern).map(Number).reduce((prev, cur, index) => {
  7.         let res = cur * prev;
  8.         return res;
  9.     } , 1);
  10.  
  11.     let coolEmojies = [];
  12.     let emojies = input.match(emojiPattern);
  13.  
  14.     for(let emoji of emojies) {
  15.         let coolenss = 0;
  16.         let chars = emoji.slice(2, -2);
  17.  
  18.         for (let char of chars) {
  19.             coolenss += char.charCodeAt(0);
  20.         }
  21.  
  22.         if(coolenss > coolTreshhold) {
  23.             coolEmojies.push(emoji);
  24.         }
  25.     }
  26.  
  27.     console.log(`Cool threshold: ${coolTreshhold}`);
  28.     console.log(`${emojies.length} emojis found in the text. The cool ones are:`);
  29.     coolEmojies.forEach(e => console.log(e));
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement