t_sh0w

02. Emoji Detector 60/100

Apr 4th, 2020
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input = []) {
  2.   let coolThreshold = 1;
  3.   let text = input.join("");
  4.  
  5.   for (let currentChar of text) {
  6.     if ("1".charCodeAt(0) <= currentChar.charCodeAt(0) && currentChar.charCodeAt(0) <= "9".charCodeAt(0)) {
  7.       coolThreshold *= Number(currentChar);
  8.     }
  9.   }
  10.   console.log(`Cool threshold: ${coolThreshold}`);
  11.  
  12.   let pattern = /([:\*]{2})[A-Z][a-z]{2,}\1/g;
  13.  
  14.   let valid = pattern.exec(text);
  15.   let counter = 0;
  16.   let coolEmojis = [];
  17.   while (valid) {
  18.     counter++;
  19.  
  20.     let emoji = valid[0].substring(2, valid[0].length - 2);
  21.     let emojiCharSum = 0;
  22.     for (let currentChar of emoji) {
  23.       emojiCharSum += currentChar.charCodeAt(0);
  24.     }
  25.     if (emojiCharSum >= coolThreshold) {
  26.       coolEmojis.push(valid[0]);
  27.     }
  28.     valid = pattern.exec(text);
  29.   }
  30.   console.log(`${counter} emojis found in the text. The cool ones are:`);
  31.   for (let current of coolEmojis) {
  32.     console.log(current);
  33.   }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment