Determining the rank of a value in collection

Hello everyone

I have built a score tracking system for a local sports club (golf). There are two courses. Everything works currently, but they want the ability to create an overall ranking between the two courses based on their ranking at each course, not their average at each course. Ie, someone has a 60 average and a 70 average, which means the are in 1st at one course, and 3rd at the other. So their overall rank score would be a 4. If someone had second at one course and 1st at the other, their overall score would be a 3, so they should be in first place on the overall ranking.

Currently I have two tables, one ranks the first course by averages, the second table ranks the other course by averages. So in the database I’m not storing rank (as in 1st, 2nd, 3rd) but averages, 60, 63, 65 etc and then filtering the data by those numbers.

How, with javascript, can I find the rank? So if one player has a 65 average, I can run some function to look through the collection and decide 65 is the 3rd by rank. My only thought so far is to query to whole database to return everything into an array, sort that array by the column in question, and return the index somehow. But maybe someone has a more efficient idea?

Any help is appreciated. Hopefully I wrote this out semi-clearly

tl:dr how can I return the rank of a number in column from database

You are right that you need to query the collection or sort your dataset by the respective columns and return item indices as described in the API here: https://www.wix.com/corvid/reference/wix-dataset.Dataset.html#getCurrentItemIndex