Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let pattern = /(?<tag>(\*){2}|(\:){2})(?<onlyWord>[A-Z][a-z]{2,})\1/gi;
- let threshold = /\d+/g;
- let emojis = [];
- let cool = 1;
- let sum = 0;
- let string = input[0].split(" ");
- let coolEmojis = [];
- for (const iterator of string) {
- let match = iterator.match(pattern);
- let thresholdMatches = threshold.exec(iterator);
- if (match != null) {
- emojis.push(match[0]);
- }
- if (thresholdMatches != null) {
- let numbers = thresholdMatches.toString().split("");
- for (let i = 0; i < numbers.length; i++) cool *= Number(numbers[i]);
- }
- }
- console.log(`Cool threshold: ${cool}`);
- for (const el of emojis) {
- let string = el.slice(2, el.length - 2);
- for (let i = 0; i < string.length; i++) {
- sum += string.charCodeAt(i);
- }
- if (sum > cool) {
- coolEmojis.push(el);
- sum = 0;
- }
- }
- console.log(
- `${
- emojis.length
- } emojis found in the text. The cool once are: \n${coolEmojis.join("\n")}`
- );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement