Created
October 22, 2017 01:33
-
-
Save joeljuca/5f4760a9499342b34e9fb408e89f0316 to your computer and use it in GitHub Desktop.
The worst method possible to process match points
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var report = ` | |
Indu 120 | |
Joel 18 | |
Rama 56 | |
-- | |
Joel 52 | |
Indu 14 | |
Rama 46 | |
-- | |
Ido 72 | |
Joel 14 | |
Rama 46 | |
-- | |
Joel 66 | |
Indu 6 | |
Ido 26 | |
-- | |
Ido 18 | |
Rama 34 | |
Indu 110 | |
-- | |
Ido 2 | |
Joel 6 | |
Indu 18 | |
-- | |
Joel 24 | |
Ido 30 | |
Rama 6 | |
-- | |
Joel 28 | |
Ido 6 | |
Rama 8 | |
` | |
report | |
.trim() | |
.toLowerCase() | |
.split('--') | |
.map(match => match | |
.trim() | |
.split('\n')) | |
.reduce((acc, match) => { | |
match.forEach(function (playerPoints) { | |
!acc[player] && acc[player] = 0 | |
var [player, points] = playerPoints.split(' ') | |
acc[player] += parseInt(points) | |
}) | |
return acc | |
}, {}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment