Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function emojiDetector(input) {
- let text = input.shift();
- let digPattern = /[0-9]/;
- let cool = 1;
- text.split('').forEach(ch => {
- if (ch.match(digPattern) !== null) {
- cool *= Number(ch.match(digPattern)[0]);
- }
- });
- console.log(`Cool threshold: ${cool}`);
- let count = 0;
- let result = [];
- let pattern = /(\:{2}|\*{2})(?<emoji>[A-Z][a-z]{2,})\1/g;
- let validList = text.matchAll(pattern);
- for (const match of validList) {
- count++;
- let coolness = (match.groups.emoji)
- .split('')
- .map(x => x.charCodeAt(0))
- .reduce((a, b) => a + b);
- if (coolness > cool) {
- result.push(match[0]);
- }
- }
- console.log(`${count} emojis found in the text. The cool ones are:`);
- result.forEach(emoji => console.log(emoji));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement