Create a function that takes an array of objects that contain a name and a date counts instances of the name for a score. Output a leaderboard of the top 10 scores. Combine the same scores together so that if, for example, first place is 20 points and two people have 20 points, show them both in first place. The order of the names in the same place are not important. Next would still be second place. For this challenge, the dates do not matter.
- The function should be of the form
f(data) => string
- The input will be an array of objects that contain the key "user" which is a string and a key "ts" which is a whole number in unix time in milliseconds.
- The actual data is in karma.json as a different file in this gist.
- Output the top 10 places (which remember that each place might include multiple users if they share the same score)
Given the following example data (again, the data you should use for the actual challenge is in a different file at the bottom of this gist):
var data = [
{
"user": "watney",
"ts": 1436310620972
},
{
"user": "watney",
"ts": 1436358918822
},
{
"user": "watney",
"ts": 1436363926303
},
{
"user": "watney",
"ts": 1436363981442
},
{
"user": "mjhagen",
"ts": 1436364513629
},
{
"user": "mjhagen",
"ts": 1436371930576
},
{
"user": "mjhagen",
"ts": 1436372686483
},
{
"user": "mjhagen",
"ts": 1436372882457
},
{
"user": "adam_cameron",
"ts": 1436372898623
},
{
"user": "adam_cameron",
"ts": 1436375428838
},
{
"user": "adam_cameron",
"ts": 1436376033686
},
{
"user": "adam_cameron",
"ts": 1436376834266
},
{
"user": "ryanguill",
"ts": 1436424381782
},
{
"user": "ryanguill",
"ts": 1436424670410
},
{
"user": "ryanguill",
"ts": 1436451749816
},
{
"user": "bdw429s",
"ts": 1436453032635
},
{
"user": "bdw429s",
"ts": 1436455704816
},
{
"user": "bdw429s",
"ts": 1436460072067
},
{
"user": "aliaspooryorik",
"ts": 1436460076928
},
{
"user": "aliaspooryorik",
"ts": 1436469597879
},
{
"user": "rodel30",
"ts": 1436523483555
}
];
you would get three people in first, two people in second, one in third and one in fourth and you would output like this:
[ #1 @ 4k ]: watney, mjhagen, adam_cameron
[ #2 @ 3k ]: bdw429s, ryanguill
[ #3 @ 2k ]: aliaspooryorik
[ #4 @ 1k ]: rodel30
(This is just example data, please do not be offended of your presense (or lack thereof) or placement in this example)
- Correctness of the result. The solution must address the problem as specified.
- Readability. This is not code golf - conciseness is good, but readable/understandable/maintainable is the goal.
- Bonus points for including unit tests.
- Further bonus points for sharing unit tests in the comments on the gist.
- Original work only.
- Submissions should be licensed under a permissive license (MIT/BSD/Apache 2.0/etc.)
- You can use any language. You can use libraries, but you should explain their usage if its not apparent.
- This is for fun and learning. There are no prizes except pride, knowledge and maybe karma.
- Submit answers in the comments of the gist as a link Gist/PasteBin/Online REPL, not in slack.
- Feel free to discuss the problem and solutions in cfml-slack in #friday-puzzle.
- If you need to clarify something about the problem or rules, do it here in the comments on the gist, or at least copy the clarification here for posterity
My first attempt: https://repl.it/EPQu/2 (javascript)