+ 19
🏆 [M💙 Challenge] SoloLearn Leaderboard System
Monday Blue 💙 Challenge Series #2 In case you don't already know, the XP ranking of SoloLearn leaderboard is quite interesting as users with the same XP will be sharing the same rank. For example, given the XP list [1, 5, 5, 6, 35, 35, 35] the leaderboard will be shown as below:- Rank 1 : 35 Rank 1 : 35 Rank 1 : 35 Rank 4 : 6 Rank 5 : 5 Rank 5 : 5 Rank 7 : 1 💼 TASK Write a program to accept an array of XP and output the leaderboard as format above. 🔧 TEST CASE ☑ [1, 5, 6, 37] 1 ▶ 37 2 ▶ 6 3 ▶ 5 4 ▶ 1 ☑ [1, 2, 2, 3] 1 ▶ 3 2 ▶ 2 2 ▶ 2 4 ▶ 1 ☑ [1, 5, 5, 6, 6, 6, 32, 32, 37] 1 ▶ 37 2 ▶ 32 2 ▶ 32 4 ▶ 6 4 ▶ 6 4 ▶ 6 7 ▶ 5 7 ▶ 5 9 ▶ 1 Happy Coding!!! 😁💻
20 Antworten
+ 3
Using function prototyping:
Array.prototype.sortXp = function() {
var cnt=1, pre;
return this.sort((a,b)=>b-a).map((v,i,a)=>{
var obv = {};
if(pre!==v) {
cnt = i + 1;
pre=v;
}
obv.rank = cnt;
obv.xp = v;
return obv;
}).map(i=>`${i.rank}:${i.xp}`);
}
https://code.sololearn.com/WPcUJR3CZWxD/?ref=app
+ 20
+ 10
https://code.sololearn.com/ch09lTv1A4Rn/#cs
+ 7
https://code.sololearn.com/cMIGEUtkp3MB/?ref=app
My Python try
+ 5
Ahh sir krishna doesn't let me do first!
+ 5
@Вукан and @Aaron both of the program got a minor bug. Please try again with the test cases above. 😉
+ 5
@Vari93 Your program run perfectly but there's a minor bug in the rank display. Please refer to the test case above. 😉
+ 4
heres mine::::::
https://code.sololearn.com/cGLk3e9b7Ywf/?ref=app
+ 4
Here's my own C# implementation! ✌
Unfortunately no LINQ this time. Thanks everyone for your participation and let's move to the next challenge! ❤
https://code.sololearn.com/cexWi7puuWj3/?ref=app
https://www.sololearn.com/Discuss/756793/?ref=app
+ 3
my practice on python https://code.sololearn.com/cloIYaGCIV5E/#py
+ 3
+ 3
Might not be the best way to do it, but I used a list to iterate through and get the highest values first.
https://code.sololearn.com/c4lBRWy571kP/?ref=app
+ 3
Here you go. Array size and array input is determined randomly.
https://code.sololearn.com/cY4bGfrGhRm3/?ref=app
+ 3
@Zephyr Koo, I'm failing to notice this bug you mentioned.
+ 2
Hmmm, okay
+ 2
Nice tries
+ 2
@Vari93 You may hard code the XP I've provided above and compare the results with your algorithm. 😉
+ 1
😎😎😎😎🗾