Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function emojiDetector(text) {
- let emojiPattern = /(::|\*\*)(?<emoji>[A-Z][a-z]{2,})\1/g;
- let thresholdPattern = /[0-9]/g;
- let emoji = emojiPattern.exec(text);
- let coolThresholdSum = 1;
- text[0]
- .match(thresholdPattern)
- .map(Number)
- .forEach((el) => (coolThresholdSum *= el));
- let countOfAllEmojis = 0;
- let result = [];
- while (emoji !== null) {
- countOfAllEmojis++;
- let currEmoji = emoji.groups.emoji;
- let coolOnes = emoji[0];
- let sum = 0;
- for (const currChar of currEmoji) {
- sum += currChar.charCodeAt();
- }
- if (sum >= coolThresholdSum) {
- result.push(coolOnes);
- }
- emoji = emojiPattern.exec(text);
- }
- console.log(`Cool threshold: ${coolThresholdSum}`);
- console.log(
- `${countOfAllEmojis} emojis found in the text. The cool ones are:`
- );
- for (const emoji of result) {
- console.log(emoji);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment