4
\$\begingroup\$

Your challenge is to query the SE API and find out whose rep on PPCG is tied, and output it. If these were all the users on PPCG:

Martin Ender: 10000 rep
Dennis: 10000 rep
xnor: 5000 rep
sp3000: 3000 rep

You should output Martin Ender, Dennis. If these were the only users:

Jon Skeet: 1000000 rep
Martin Ender: 10000 rep
Dennis: 10000 rep
xnor: 5000 rep
sp3000: 3000 rep
Digital Trauma: 2000 rep
Luis Mendo: 2000 rep
Helka Homba: 2000 rep

You should output:

Martin Ender, Dennis
Digital Trauma, Luis Mendo, Helka Homba

Note that you can use different output formats, as long as it is clear whose rep is tied and who they are tied with. Users with <200 rep can be ignored.

\$\endgroup\$
5
  • 7
    \$\begingroup\$ Please consider using the Sandbox in the future to get feedback on your challenges before posting them to the main site. \$\endgroup\$
    – user45941
    May 10, 2017 at 18:04
  • \$\begingroup\$ Are we only supposed to get users from PPCG? \$\endgroup\$
    – hyper-neutrino
    May 10, 2017 at 18:05
  • \$\begingroup\$ @HyperNeutrino yes, only PPCG. \$\endgroup\$
    – user58826
    May 10, 2017 at 18:07
  • 3
    \$\begingroup\$ "Users with <200 rep can be ignored." Can be ignored or should be ignored? \$\endgroup\$
    – Shaggy
    May 11, 2017 at 8:49
  • 1
    \$\begingroup\$ When you say we can use different output formats, does that include using something other than their name to identify each user? \$\endgroup\$
    – Shaggy
    May 11, 2017 at 15:34

1 Answer 1

2
\$\begingroup\$

JavaScript (ES6), 259 257 248 241 bytes

Returns a Promise object containing \n separated groups, in ascending order of reputation, of profile links for users with the same rep, with each link separated by a comma. As the question only states that users with 200 reputation or less can be ignored (rather than should be ignored), this solution includes a couple of users who do have <200 rep.

f=(x=95,s="",c=0)=>fetch(`//api.stackexchange.com/users?page=${x}&site=codegolf`).then(a=>a.json()).then(j=>(i=j.items.reverse()).map(x=>(r=x.reputation)>c?(c=r,t.length-1&&(s+=t+`
`),t=[x.link]):t.push(x.link),t=[i[0].link])&--p?f(p,s,c):s)

Caveat

Between this challenge, "Martin vs. Dennis" and a couple of others, I've managed to get myself (temporarily) booted from the API for a few hours! I was, therefore, unable to run my final tests on this but it should be working (although, I suspect it might not include users from page 1 in the output). There's probably a bit more I can golf off it, so I'll come back to it when my ban is lifted.


Try it

WARNING: The first Snippet below will submit 95(!) requests to the SE API - running it a couple of times may result in you also having your access to the API temporarily revoked. If you'd prefer to test this with a reduced number of API calls and, therefore, a reduced result set, change the value of the first parameter to something much lower than 95. Alternatively, you can test it with no API calls, using the second batch of sample data from the question by using the second Snippet below, which returns usernames instead of profile links (for now).


f=(x=95,s="",c=0)=>fetch(`//api.stackexchange.com/users?page=${x}&site=codegolf`).then(a=>a.json()).then(j=>(i=j.items.reverse()).map(x=>(r=x.reputation)>c?(c=r,t.length-1&&(s+=t+`
`),t=[x.link]):t.push(x.link),t=[i[0].link])&--p?f(p,s,c):s)
f().then(console.log)


f=(x=95,s="",c=0)=>Promise.resolve(JSON.parse(`{"items":[{"display_name":"John Skeet","reputation":1000000},{"display_name":"Martin Ender","reputation":10000},{"display_name":"Dennis","reputation":10000},{"display_name":"xnor","reputation":5000},{"display_name":"sp3000","reputation":3000},{"display_name":"Digital Trauma","reputation":2000},{"display_name":"Luis Mendo","reputation":2000},{"display_name":"Helka Homba","reputation":2000}]}`)).then(j=>(i=j.items.reverse()).map(y=>(r=y.reputation)>c?(c=r,t.length-1&&(s+=t+`
`),t=[y.display_name]):t.push(y.display_name),t=[i[0].display_name])&--x?f(x,s,c):s)
f().then(console.log)

\$\endgroup\$
2
  • \$\begingroup\$ Drop the the parens on fetch to save 2 bytes \$\endgroup\$ May 11, 2017 at 16:52
  • 1
    \$\begingroup\$ @JohanKarlsson, that won't work due to the ${x} being used to construct the URL. \$\endgroup\$
    – Shaggy
    May 11, 2017 at 17:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.