Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function emojiDetector([string]) {
- let regexEmoji = /(::|\*\*)([A-Z][a-z]{2,})\1/g;
- let regexNumbers = /[0-9]/g;
- let arrEmoji = [];
- let emojiObject = {};
- let countEmojis = 0;
- let matchEmoji = regexEmoji.exec(string);
- let matchNumbers = string.match(regexNumbers).map((n) => Number(n));
- let coolNumber = matchNumbers.reduce((a, b) => a * b);
- console.log(`Cool threshold: ${coolNumber}`);
- while (matchEmoji) {
- arrEmoji.push(matchEmoji[0]);
- emojiObject[matchEmoji[0]] = 0;
- matchEmoji = regexEmoji.exec(string);
- }
- for (let emoji of arrEmoji) {
- countEmojis++;
- let sum = 0;
- for (let i = 0; i < emoji.length; i++) {
- let letterASCII = emoji[i].charCodeAt();
- sum += letterASCII;
- }
- emojiObject[emoji] = sum;
- }
- console.log(`${countEmojis} emojis found in the text. The cool ones are:`);
- for (let emoji in emojiObject) {
- if (emojiObject[emoji] >= coolNumber) {
- console.log(emoji);
- }
- }
- }
- emojiDetector([
- "5, 4, 3, 2, 1, go! The 1-th consecutive banana-eating contest has begun! ::Joy:: **Banana** ::Wink:: **Vali** ::valid_emoji::",
- ]);
Advertisement
Add Comment
Please, Sign In to add comment