I'm using the Javascript sorting to sort an array of objects. This is why i'm trying to do (take the 10 best players in my array) :
this.topPlayers .sort(function(a, b) {
return a.stars > b.stars;
});
this.topPlayers = this.topPlayers.slice(0,10);
It returns me the same thing when i'm doing this (the 10 worst players) :
this.topPlayers .sort(function(a, b) {
return a.stars < b.stars;
});
this.topPlayers = this.topPlayers.slice(0,10);
What am I doing wrong ? Same results in both case, tried to sort on other properties, again same result... I'm using angular and doing it on ngOnInit() function.
this.topPlayersand.sort(. I'm sure that's a transcription error, but thought I'd point it out.a.starstype value ? string, number ? date ? object? array ?return a.stars - b.starsorreturn b.stars - a.stars