5 kyu
Whole of Names
Description:
So unfair ! Other players with same score as you, may put you out of the Hall due to name-sorting-rule ! ! ! (better to be named anjinxin than zozo...)
Things should change now !
Task
Create a function hallOfFame(players)
which return an ordered list of sub-arrays of players with same score.
Input :
- list of
players
- each
player
is a 2-items array of the form[name, score]
Output :
- list of 3 best
ranks
- each
rank
is an array of the form[score, name1 (,name2, (name3,...) )]
with names of each player with same score. ranks
should be sorted from best score (==higher) to "worst" (lower).
eg:
hallOfFame(["Aya",5], ["Ben",9], ["Clo",5], ["Dan",7]) // -> [ [9,"Ben"], [7, "Dan"], [5, "Aya", "Clo"] ]
- when more than 1 player have the same score, they should be sorted alphabeticaly (
[42, "Xin","Yang","Zhu"] not [42, "Yang", "Zhu", "Xin"]
)
Important
In case of equality in first places, next ones will be moved. It means :
- If 2 players share the 1st rank, next one(s) move to 3rd rank.
- If more than 2 players share the 1st rank other players can't figure on the podium.
- If there is only one "1st player" but more than one "2d players" then "3rd" rank is inoccupied.
In these cases "empty" ranks should figure in returned array as empty sub-arrays : [ [123,"Xin","Yang","Zhu"], [], [] ]
Examples :
hallOfFame(["Aya",9], ["Ben",9], ["Clo",9], ["Dan",8.99])
// -> [ [9, "Aya", "Ben", "Clo"], [], [] ] : 3 players on 1st place no 2nd nor 3rd rank allowed)
hallOfFame(["Aya",9], ["Ben",9], ["Clo",8], ["Dan",7.99])
// -> [ [9,"Aya","Ben"], [], [8,"Clo"] ] : 2 players on 1st place -> "2nd" score goes to 3rd rank
hallOfFame(["Aya",9], ["Ben",8], ["Clo",8], ["Dan",7.99])
// -> [ [9,"Aya"], [8,"Ben","Clo"], [] ] : 1 "1st player", 2 "2nd players" -> no place for the 3rd
hallOfFame(["Aya",9], ["Ben",8], ["Clo",7], ["Dan",6.99])
// -> [ [9,"Aya"], [8,"Ben"], [7,"Clo"] ] : each first places occupied by only 1 player
Don't give up, stay in the Top !
Arrays
Fundamentals
Similar Kata:
Stats:
Created | Sep 6, 2017 |
Published | Sep 6, 2017 |
Warriors Trained | 254 |
Total Skips | 9 |
Total Code Submissions | 1033 |
Total Times Completed | 99 |
JavaScript Completions | 99 |
Total Stars | 14 |
% of votes with a positive feedback rating | 94% of 42 |
Total "Very Satisfied" Votes | 37 |
Total "Somewhat Satisfied" Votes | 5 |
Total "Not Satisfied" Votes | 0 |
Total Rank Assessments | 8 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 7 kyu |