Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function emojiDecoder(input) {
- const thresholdPattern = /[\d+]/gm;
- let threshold = 1;
- let thresholdMatch;
- while ((thresholdMatch = thresholdPattern.exec(input))) {
- threshold *= Number(thresholdMatch[0]);
- }
- const emojiPattern = /(:{2}|\*{2})([A-Z][a-z]{2,})(\1)/gm;
- const emojies = [];
- let validEmojies;
- while ((validEmojies = emojiPattern.exec(input))) {
- emojies.push(validEmojies[0]);
- }
- console.log(`Cool threshold: ${threshold}`);
- console.log(`${emojies.length} emojis found in the text. The cool ones are:`);
- emojies.filter((emoji) => isCoolEmoji(emoji)).forEach(e => {
- console.log(e);
- });
- function isCoolEmoji(emoji) {
- const coolness = emoji.split('').reduce((acc, ch) => {
- if (ch !== ':' && ch !== '*') {
- acc += ch.charCodeAt();
- }
- return acc;
- }, 0);
- if (coolness > threshold) {
- return true;
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement