Advertisement
Guest User

E

a guest
Apr 4th, 2020
159
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-Za-z]{3,})\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.     let coolEmojis = [];
  13.     for (let line of emojis) {
  14.         let currLine = line;
  15.         if (line.includes('**')) {
  16.             let start = '\\**';
  17.             let regex = new RegExp(start, 'g')
  18.             line = line.replace(regex, "")
  19.         } else if (line.includes('::')) {
  20.             let end = '\\::';
  21.             let reg = new RegExp(end, 'g');
  22.             line = line.replace(reg, '')
  23.         }
  24.         let currAscii =  0;
  25.         for (let char of line) {
  26.            let value = char.charCodeAt(0);
  27.             currAscii += value;
  28.         }
  29.         if (currAscii > coolThreshold) {
  30.             coolEmojis.push(currLine);
  31.         }
  32.     }
  33.     console.log(`Cool threshold: ${coolThreshold}`);
  34.     console.log(`${emojis.length} emojis found in the text. The cool ones are:`);
  35.     console.log(`${coolEmojis.join('\n')}`);
  36.        
  37.    
  38.    
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement