Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let [text, encryptedEmoji] = input;
- let decryptedEmoji = decryptEmoji();
- let pattern = /(?<=\s):([a-z]{4,}):(?=[\s,.!?])/g;
- let allEmojis = [];
- let totalPower = 0;
- function sumAsciiCode(emoji) {
- let sum = emoji.split('').map(e => e.charCodeAt(0)).reduce((a, b) => a + b, 0);
- return sum;
- }
- function decryptEmoji() {
- let output = ':'
- let asciiCodes = encryptedEmoji.split(':').map(Number);
- let emoji = asciiCodes.map(e => String.fromCharCode(e)).join('');
- output = output + emoji + ':';
- return output;
- }
- let matches = pattern.exec(text);
- while (matches !== null) {
- let [emoji, emojiLetters] = matches;
- allEmojis.push(emoji);
- let currentPower = sumAsciiCode(emojiLetters);
- totalPower += currentPower;
- matches = pattern.exec(text);
- }
- if (allEmojis.includes(decryptedEmoji)) {
- totalPower = totalPower * 2;
- }
- if (allEmojis.length > 0) {
- console.log(`Emojis found: ${allEmojis.join(', ')}`);
- }
- console.log(`Total Emoji Power: ${totalPower}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement