Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
961
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. function emojiDetector(input) {
  2. let text = input.shift();
  3. let digPattern = /[0-9]/;
  4. let cool = 1;
  5. text.split('').forEach(ch => {
  6. if (ch.match(digPattern) !== null) {
  7. cool *= Number(ch.match(digPattern)[0]);
  8. }
  9. });
  10. console.log(`Cool threshold: ${cool}`);
  11. let count = 0;
  12. let result = [];
  13. let pattern = /(\:{2}|\*{2})(?<emoji>[A-Z][a-z]{2,})\1/g;
  14. let validList = text.matchAll(pattern);
  15. for (const match of validList) {
  16. count++;
  17. let coolness = (match.groups.emoji)
  18. .split('')
  19. .map(x => x.charCodeAt(0))
  20. .reduce((a, b) => a + b);
  21. if (coolness > cool) {
  22. result.push(match[0]);
  23. }
  24. }
  25. console.log(`${count} emojis found in the text. The cool ones are:`);
  26. result.forEach(emoji => console.log(emoji));
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement