Making a simple leader board in memory
Your implementation depends on this.leaderboard.sort((a, b) =&gt; a.score - b.score);. Each and every time you insert, you sort again.

Depending on your access pattern, you could defer the sorting from adding to reading.

You could operate with a dictionary keeping the scores unorderd which makes inserting fast. And sort the entries only in case if you read them.

For the sake of the example I used plain numbers

let leaderboard = {
}

const addScore = (board, score) =&gt; {
  if(!board[score]) board[score] = []
  board[score].push(score)
  return board;
}

const getcurrentRanks = (board) =&gt; {
    const scoreranks = Object.keys(board).sort((a,b)=&gt;b-a)
    return scoreranks.reduce((o,n )=&gt;{
        return o.concat(board[n]);
    }, []);
}


But this has the downside of converging to your first implementation the more you read; e.g. for each time you insert a value you want to get all the ranks.

Otherwise I would encourage you to look into priority queues.