Reputation: 1
I hope anybody can help. I want to rank (13) scores (variables) that are determined through an assessment. The scores then need to be ranked (descending order) and then match to variables RankOne, RankTwo, etc.
var player = GetPlayer();
Upvotes: 0
Views: 272
Reputation: 13631
Which part are you struggling with?
const scores = [17, 98, 45, 41, 67, 12, 39, 90, 11, 25, 83, 77, 53];
scores.sort().reverse();
const rankOne = scores[0];
const rankTwo = scores[1];
const rankThree = scores[2];
console.log(rankOne, rankTwo, rankThree);
// 98 90 83
If you don't want to alter scores
then copy it instead using [...scores]
or slice()
before sorting:
const scoresDescending = scores.slice().sort().reverse();
Upvotes: 0