infoshareacademy / jfdd13-dreamteam

1 stars 4 forks source link

trouble with organising data when adding a highscore to the middle of the list #20

Closed aleksanderwalczuk closed 4 years ago

aleksanderwalczuk commented 4 years ago

19

I've got some trouble with highscores. Now let me show you an example: this is an actual highscore list

  1. John 300 points
  2. Sarah 222 points
  3. Tom 100

// now I want to add another name with score, but let's say that we keep up to 3 highest scores and the score I want to add is the highest

this is a new list

  1. Mark 500 points
  2. John 300 points
  3. Sarah 222 points

// Tom is gone, but the rest has dropped one place below (John is 2, etc...)

It gets even more complex when we have ten scores and put a new one in the middle of the list (all below drop, but higher stays on the same place)

Any ideas? I already have a few, but for sure they're complex, unoptimised and the performance is a horror :)

@aszablowski , @miklosz , @michal-kusnierz , @cytrowski , @martyna-michno , @krichert

Originally posted by @Rednaxela700 in https://github.com/infoshareacademy/jfdd13-dreamteam/pull/19#issuecomment-566006522

cytrowski commented 4 years ago

If you keep highscores in the localstorage then load them into array, add the new highscore to that array, sort and put it back in the localstorage. Then clear the list on a screen and render it from scratch :) Should be good enough ;)

aleksanderwalczuk commented 4 years ago

Thank you so much!

aleksanderwalczuk commented 4 years ago

Works like a charm, thanks for your attention.