I am trying to write an function to sort an array like this:
[
{score:10, name:foo},
{score:-10, name:bar},
{score:0, name:newNAME}
]
into
[
{rank:1, score:10, name:foo},
{rank:2, score:0, name:newNAME},
{rank:3, score:-10, name:bar}
]
But i found it is difficult to access the key(using score to sort and add a rank into each object).Is anyone can give me some hints to write such function?