Guest User

Untitled

a guest
Oct 22nd, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. var report = `
  2. Indu 120
  3. Joel 18
  4. Rama 56
  5. --
  6. Joel 52
  7. Indu 14
  8. Rama 46
  9. --
  10. Ido 72
  11. Joel 14
  12. Rama 46
  13. --
  14. Joel 66
  15. Indu 6
  16. Ido 26
  17. --
  18. Ido 18
  19. Rama 34
  20. Indu 110
  21. --
  22. Ido 2
  23. Joel 6
  24. Indu 18
  25. --
  26. Joel 24
  27. Ido 30
  28. Rama 6
  29. --
  30. Joel 28
  31. Ido 6
  32. Rama 8
  33. `
  34.  
  35. report
  36. .trim()
  37. .toLowerCase()
  38. .split('--')
  39. .map(match => match
  40. .trim()
  41. .split('\n'))
  42. .reduce((acc, match) => {
  43. match.forEach(function (playerPoints) {
  44. !acc[player] && acc[player] = 0
  45. var [player, points] = playerPoints.split(' ')
  46. acc[player] += parseInt(points)
  47. })
  48. return acc
  49. }, {})
Add Comment
Please, Sign In to add comment