Advertisement
Guest User

E

a guest
Apr 4th, 2020
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve (input = []) {
  2.     let text = input.shift();
  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.         if (line.includes('**')) {
  17.             let start = '\\**';
  18.             let regex = new RegExp(start, 'g')
  19.             line = line.replace(regex, "")
  20.         } else if (line.includes('::')) {
  21.             let end = '\\::';
  22.             let reg = new RegExp(end, 'g');
  23.             line = line.replace(reg, '')
  24.         }
  25.         let currEmoji = line.split('');
  26.         let currAscii =  0;
  27.         currEmoji.forEach(letter => {
  28.             letter = letter.charCodeAt(0);
  29.             currAscii += letter;
  30.         });
  31.         if (currAscii >= coolThreshold) {
  32.             coolEmojis.push(currLine);
  33.         }
  34.     }
  35.     console.log(`Cool threshold: ${coolThreshold}`);
  36.     console.log(`${emojis.length} emojis found in the text. The cool ones are:`);
  37.     if (coolEmojis.length > 0) {
  38.         console.log(`${coolEmojis.join('\n')}`);
  39.        
  40.     }
  41.    
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement