Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve (input = []) {
  2.     let text = input[0];
  3.     let patternNumbers = /([0-9])/g;
  4.     let patternEmojis = /([:*]{2})([A-Z][a-z]{2,})\1/g
  5.     let nums = text.match(patternNumbers);
  6.     let emojis = text.match(patternEmojis);
  7.     let coolThreshold = 1;
  8.     for (let num of nums) {
  9.         num = Number(num);
  10.         coolThreshold *= num;
  11.     }
  12.  
  13.     let coolEmojis = [];
  14.     for (let line of emojis) {
  15.         //let currLine = line;
  16.         let regexL = /[A-Z][a-z]{2,}/;
  17.         let coolEmoji = line.match(regexL);
  18.         //console.log(coolEmoji);
  19.        
  20.         let currEmoji = coolEmoji[0].split('');
  21.         let currAscii =  0;
  22.         currEmoji.forEach(letter => {
  23.             letter = letter.charCodeAt(0);
  24.             currAscii += letter;
  25.         });
  26.         if (currAscii >= coolThreshold) {
  27.             coolEmojis.push(line);
  28.         }
  29.     }
  30.     console.log(`Cool threshold: ${coolThreshold}`);
  31.     console.log(`${emojis.length} emojis found in the text. The cool ones are:`);
  32.     if (coolEmojis.length > 0) {
  33.         console.log(`${coolEmojis.join('\n')}`);
  34.        
  35.     }
  36.    
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement