Advertisement
Guest User

Untitled

a guest
Jun 20th, 2023
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.     let digitArr = []
  3.     let coolEmojies = []
  4.     let count = 0
  5.     let threshold = 0
  6.     input.map(x => {
  7.         //let pattern = /([:|\*]{2})(?<emos>[A-Z][a-z]{2,})(\1)/g
  8.         let pattern = /(\*{2}|:{2})(?<emos>[A-Z][a-z]{2,})(\1)/g
  9.         const patternLetters = /[a-zA-Z]/g;
  10.         let digits = /\d/g
  11.         //let line = pattern.exec(x);
  12.         let line = x.match(pattern)
  13.         let finalDigits = x.match(digits)
  14.         digitArr.push(finalDigits)
  15.         digitArr.map(x => {
  16.             threshold = x.map(Number).reduce((a, v) => a * v)
  17.         })
  18.         //  if(line){
  19.         //   count++
  20.         //  let emojis = line.groups.emos  emojis = emojis.match(patternLetters).map(y => y.charCodeAt())
  21.         for (i = 0; i < line.length; i++) {
  22.             let emojis = line[i]
  23.             emojis = emojis.match(patternLetters).map(y => y.charCodeAt())
  24.             // let sumOfChars = emojis.map(Number).reduce((a, v) => a * v)
  25.             let sumOfChars = emojis.map(Number).reduce((a, v) => a + v)
  26.             if (sumOfChars > threshold) {
  27.                 //coolEmojies.push(line[0]);
  28.                 coolEmojies.push(line[i]);
  29.             }
  30.         }
  31.         console.log(`Cool threshold: ${threshold}`)
  32.         //console.log(`${count} emojis found in the text. The cool ones are:`);
  33.         console.log(`${line.length} emojis found in the text. The cool ones are:`);
  34.         console.log(coolEmojies.join("\n"));
  35.         // }
  36.  
  37.     })
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement