Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.  
  3.     let emojiPattern = /(::|\*\*)([A-Z][a-z]{2,})\1/g;
  4.  
  5.     let numPattern = /\d/g;
  6.  
  7.     let matchedEmoji = [...input[0].matchAll(emojiPattern)];
  8.     let matchedNums = [...input[0].matchAll(numPattern)];
  9.  
  10.     let emojiArr = [];
  11.     let numArr = [];
  12.     let symArr = [];
  13.  
  14.     for (let i = 0; i < matchedEmoji.length; i++) {
  15.  
  16.         emojiArr.push(matchedEmoji[i][2]);
  17.         symArr.push(matchedEmoji[i][1])
  18.  
  19.     }
  20.  
  21.     for (let i = 0; i < matchedNums.length; i++) {
  22.  
  23.         numArr.push(matchedNums[i][0])
  24.     }
  25.  
  26.     let cool = 1;
  27.  
  28.     for (const line of numArr) {
  29.         cool *= Number(line);
  30.     }
  31.  
  32.     console.log(`Cool threshold: ${cool}`);
  33.     console.log(`${emojiArr.length} emojis found in the text. The cool ones are:`);
  34.    
  35.     for (let i = 0; i < emojiArr.length; i++) {
  36.  
  37.        
  38.        
  39.         let asciiLine = emojiArr[i].split('').map(x => x.charCodeAt(0));
  40.  
  41.         let value = 0;
  42.  
  43.         for (const num of asciiLine) {
  44.             value += num;
  45.         }
  46.  
  47.         if (value > cool) {
  48.             console.log(`${symArr[i]}${emojiArr[i]}${symArr[i]}`);
  49.            
  50.         }  
  51.     }
  52.    
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement