Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function smile(input) {
- const digits = input[0].match(/\d/g);
- let threshold = BigInt;
- if (digits) {
- threshold = digits.map(Number).reduce((acc, curr) => acc * curr, 1);
- } else {
- threshold = 0
- }
- console.log(`Cool threshold: ${threshold}`);
- const emojiPattern = /(::|\*\*)([A-Z][a-z]{2,})\1/g
- const emojis = input[0].matchAll(emojiPattern);
- if (emojis) {
- const coolEmojis = [];
- let count = 0;
- for (const emj of emojis) {
- // console.log(emj);
- count++;
- const emojiSum = emj[2].split('').reduce((sum, currEmj) => sum + currEmj.charCodeAt(0), 0);
- // console.log(emojiSum);
- if (emojiSum >= threshold) {
- coolEmojis.push(emj[0]);
- }
- }
- let output = `${count} emojis found in the text. The cool ones are:`;
- coolEmojis.forEach(coolEmj => output += `\n${coolEmj}`);
- return output;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement