dabidabidesh

emoji

Jul 31st, 2020
357
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Programming Fundamentals Final Exam - 04 April 2020 Group 1/02. Emoji Detector.js
  2. emojiDetector = inputArray => {
  3.   'use strict'
  4.  
  5.   const isColl = emojiStr => {
  6.     let sumAscii = 0
  7.     for (let i = 2; i < emojiStr.length - 2; i++) {
  8.       sumAscii += emojiStr[i].charCodeAt(0)
  9.     }
  10.     if (sumAscii > coolThresholdProduct)
  11.       return true
  12.   }
  13.  
  14.   let coolThresholdProduct = 1
  15.   let digitPattern = /\d/g
  16.   let digit = inputArray[0].match(digitPattern)
  17.  
  18.   for (const i of digit)
  19.     coolThresholdProduct *= i
  20.  
  21.   console.log(`Cool threshold: ${coolThresholdProduct}`)
  22.  
  23.   let emojiPattern = /(::|\*\*)[A-Z][a-z]{2,}\1/g
  24.   let emojis = inputArray[0].match(emojiPattern)
  25.  
  26.   console.log(`${emojis.length} emojis found in the text. The cool ones are:`)
  27.  
  28.   for (const i of emojis) {
  29.     if (isColl(i))
  30.       console.log(i)
  31.   }
  32. }
RAW Paste Data