Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input = []) {
- let coolThreshold = 1;
- let text = input.join("");
- for (let currentChar of text) {
- if ("1".charCodeAt(0) <= currentChar.charCodeAt(0) && currentChar.charCodeAt(0) <= "9".charCodeAt(0)) {
- coolThreshold *= Number(currentChar);
- }
- }
- console.log(`Cool threshold: ${coolThreshold}`);
- let pattern = /([:\*]{2})[A-Z][a-z]{2,}\1/g;
- let valid = pattern.exec(text);
- let counter = 0;
- let coolEmojis = [];
- while (valid) {
- counter++;
- let emoji = valid[0].substring(2, valid[0].length - 2);
- let emojiCharSum = 0;
- for (let currentChar of emoji) {
- emojiCharSum += currentChar.charCodeAt(0);
- }
- if (emojiCharSum >= coolThreshold) {
- coolEmojis.push(valid[0]);
- }
- valid = pattern.exec(text);
- }
- console.log(`${counter} emojis found in the text. The cool ones are:`);
- for (let current of coolEmojis) {
- console.log(current);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment