+ 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!!! 😁💻

16th Oct 2017, 1:28 PM
Zephyr Koo
Zephyr Koo - avatar
20 Answers
+ 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
25th Sep 2017, 8:26 AM
Calviղ
Calviղ - avatar
25th Sep 2017, 1:40 AM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 10
https://code.sololearn.com/ch09lTv1A4Rn/#cs
26th Sep 2017, 12:08 AM
Vukan
Vukan - avatar
25th Sep 2017, 4:54 AM
Martin Möhle
Martin Möhle - avatar
+ 7
https://code.sololearn.com/cMIGEUtkp3MB/?ref=app My Python try
25th Sep 2017, 3:34 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 5
Ahh sir krishna doesn't let me do first!
25th Sep 2017, 3:29 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 5
@Вукан and @Aaron both of the program got a minor bug. Please try again with the test cases above. 😉
26th Sep 2017, 6:46 AM
Zephyr Koo
Zephyr Koo - avatar
+ 5
@Vari93 Your program run perfectly but there's a minor bug in the rank display. Please refer to the test case above. 😉
29th Sep 2017, 9:28 AM
Zephyr Koo
Zephyr Koo - avatar
25th Sep 2017, 4:07 AM
sayan chandra
sayan chandra - avatar
+ 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
2nd Oct 2017, 3:34 AM
Zephyr Koo
Zephyr Koo - avatar
25th Sep 2017, 3:22 PM
ysraelcon
ysraelcon - avatar
25th Sep 2017, 5:55 PM
Samuel Šúr
Samuel Šúr - avatar
+ 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
26th Sep 2017, 2:16 AM
Aaron Icenhour
Aaron Icenhour - avatar
26th Sep 2017, 5:41 AM
Lost Net (Mirkn)
Lost Net (Mirkn) - avatar
+ 3
Here you go. Array size and array input is determined randomly. https://code.sololearn.com/cY4bGfrGhRm3/?ref=app
29th Sep 2017, 9:18 AM
Vari93
Vari93 - avatar
+ 3
@Zephyr Koo, I'm failing to notice this bug you mentioned.
2nd Oct 2017, 3:41 AM
Vari93
Vari93 - avatar
+ 2
Hmmm, okay
25th Sep 2017, 1:22 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 2
Nice tries
26th Sep 2017, 5:28 PM
Kushagra Pankajrai Bothra
Kushagra Pankajrai Bothra - avatar
+ 2
@Vari93 You may hard code the XP I've provided above and compare the results with your algorithm. 😉
2nd Oct 2017, 4:06 AM
Zephyr Koo
Zephyr Koo - avatar
+ 1
😎😎😎😎🗾
28th Sep 2017, 5:44 PM
Вадим Семенов
Вадим Семенов - avatar