Advertisement
KrasimirKosturkov

Untitled

Apr 6th, 2020
209
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 firstPattern = /(\d)/g;
  4.    let array;
  5.    let count = 0;
  6.    let number = 0;
  7.    let emojiPattern = /(\*{2}|:{2})([A-Z][a-z]{2,})(\1)/g;
  8.    let arr;
  9.    let coolest = [];
  10.    let newArr = '';
  11.    for(let line of input){
  12.       while((array = firstPattern.exec(line)) !== null){
  13.           coolThresHold *= +(array[1]);
  14.       }
  15.       while((arr = emojiPattern.exec(line))!== null){
  16.         count++;
  17.         newArr = arr[2];
  18.         for(let i = 0; i < newArr.length; i++){
  19.           number += newArr[i].charCodeAt(0);
  20.           if(number > coolThresHold){
  21.              coolest.push(arr[0]);
  22.              break;
  23.         }
  24.       }
  25.       number = 0;
  26.     }
  27.    }
  28.    console.log(`Cool threshold: ${coolThresHold}`);
  29.    console.log(`${count} emojis found in the text. The cool ones are:`);
  30.    if(coolest.length > 0){
  31.    console.log(coolest.join('\n'));
  32.    }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement