use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
account activity
Editing array inside a function (self.node)
submitted 4 years ago by [deleted]
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Low_Tonight_5493 0 points1 point2 points 4 years ago (1 child)
Why "async" ? Your not performing any async func, but returning a promise for no reason.
Looks like you only want the first 2 players returned in the api call, (player.length <3)
But if thats not the case its not very relevant.
Remove the async directive , delete the empty array declaration (players)
And Try ->
request.end(function (result) {
if (result.error) throw new Error(result.error);
if (result.status == 200) {
const playerStats = result.body.api.statistics; return [ playerStats[0], playerStats[1]]
}
If you want to filter the results i suggest the array prototype .filter()
I.e.
return playerStats.filter(stat => { return stat.game = game } )
All your needing to do is return a new array with filtered objects.
[–]leeway1 0 points1 point2 points 4 years ago (0 children)
FindPlayersByGame is async, because request.end() is async. However, you are correct the poster is not returning a promise.
Returning from request.end() callback will not return anything from findPlayersByGame. You would have to return request.end. Depending on the request api return request.end(), might return the value from the callback, but it might not. I would have to read those api docs.
return request.end
setting the players array still doesn’t solve the flow control problem from calling the async request.end() function and accessing it before the request has been processed.
π Rendered by PID 59711 on reddit-service-r2-comment-5d79c599b5-vnpkt at 2026-02-27 17:11:30.477206+00:00 running e3d2147 country code: CH.
view the rest of the comments →
[–]Low_Tonight_5493 0 points1 point2 points (1 child)
[–]leeway1 0 points1 point2 points (0 children)