Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. function solve(input) {
  2. let sum = 0;
  3. let text = input.shift();
  4. let pattern = /[,.!? ]:([a-z]){4,}:[,.!? ]/g;
  5. let foundEmojis = text.match(pattern);
  6.  
  7. let pesho=[];
  8. let emoji = input.shift()
  9. .split(':')
  10. .forEach((el)=>{
  11. el=String.fromCharCode(el);
  12. pesho.push(el);
  13. })
  14. pesho=pesho.join('');
  15. let emo=[];
  16.  
  17. if (foundEmojis) {
  18. for (let i = 0; i < foundEmojis.length; i++) {
  19. let all = foundEmojis[i].split(':');
  20. all=all[1];
  21.  
  22. for (let result of all) {
  23. let chars = result.charCodeAt(0);
  24. sum += chars;
  25. }
  26.  
  27.  
  28. all=`:${all}:`
  29. emo.push(all);
  30. }
  31. }
  32.  
  33. if (sum > 0) {
  34.  
  35. emo.forEach((element)=>{
  36. element=element.split(':');
  37. let currentEmoji=element[1];
  38.  
  39. if(currentEmoji=== pesho){
  40. sum*=2;
  41. }
  42. })
  43. console.log(`Emojis found: ${emo.join(', ')}`);
  44. }
  45. console.log(`Total Emoji Power: ${sum}`);
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement