Advertisement
Guest User

Untitled

a guest
Jul 29th, 2019
207
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.  
  3. let finalWord = input.pop();
  4.  
  5. const convertToAscii = (string) => {
  6.  
  7. let output = [];
  8. let result = "";
  9.  
  10. const arr = string.split(":");
  11.  
  12. arr.forEach((line) => {
  13. let current = String.fromCharCode(Number(line));
  14. output.push(current);
  15. });
  16.  
  17. return result += output.join('');
  18.  
  19. };
  20.  
  21. finalWord = ':'+convertToAscii(finalWord)+':';
  22.  
  23. const findAllEmoji = (string) => {
  24.  
  25. let pattern = /\s(:[a-z]{4,}:)[\s,.!?]/gm;
  26. let validEmojis = [];
  27. let validEmoji = null;
  28.  
  29. while ((validEmoji = pattern.exec(string)) !== null) {
  30. validEmojis.push(validEmoji[1]);
  31. }
  32.  
  33. return validEmojis;
  34. };
  35.  
  36. let validEmojisArray = findAllEmoji(input);
  37.  
  38. const sumAllLetters = (line) => {
  39.  
  40. let sum = 0;
  41. let totalSum = 0;
  42.  
  43. line.forEach((elem) => {
  44. for (let i = 0; i < elem.length; i++) {
  45.  
  46. let current = Number(elem.charCodeAt(i));
  47. sum += current;
  48. }
  49. sum -=116
  50. });
  51.  
  52. return sum;
  53. };
  54.  
  55. let totalSum = sumAllLetters(validEmojisArray);
  56.  
  57. if(validEmojisArray.includes(finalWord)) {
  58. totalSum *=2;
  59. }
  60.  
  61.  
  62. if(validEmojisArray.length > 0) {
  63. console.log(`Emojis found: ${validEmojisArray.join(", ")}`);
  64. }
  65. console.log(`Total Emoji Power: ${totalSum}`);
  66.  
  67. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement