voodoodan Posted September 23, 2015 Share Posted September 23, 2015 Hello, I'm trying to make some kind of leaderboard, such as the example below: var game = ["Dominoes",95,"Cards",22,"Chess",65]; The idea is to try to group all of the numbers together in the array so that I can return a position on them. For example: 95 - would return 1st place (for the most points) 65 - 2nd place 22 - 3rd place But the numbers in the "game" variable would also need to be linked in with the games so that if they were sorted numerically then the games would follow suit as well. Would anyone be able to help with this, please? I'd be grateful for any assistance. Many thanks,Dan. Link to comment Share on other sites More sharing options...
davej Posted September 23, 2015 Share Posted September 23, 2015 I would think you would need a separate array for each game. Link to comment Share on other sites More sharing options...
Ingolme Posted September 23, 2015 Share Posted September 23, 2015 A different data structure would be needed. Something like this, for example: var game = [ { name: "Dominoes", score: 95 }, { name: "Cards", score: 22 }, { name: "Chess", score: 65 }]; Then you could use the sort() method and pass in a function that compares the scores of each item. 1 Link to comment Share on other sites More sharing options...
voodoodan Posted September 24, 2015 Author Share Posted September 24, 2015 A different data structure would be needed. Something like this, for example: var game = [ { name: "Dominoes", score: 95 }, { name: "Cards", score: 22 }, { name: "Chess", score: 65 }]; Then you could use the sort() method and pass in a function that compares the scores of each item. Thanks very much for this Ingolme, I'll give that structure a go. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now