5 kyu

Whole of Names

Description:

The Return of the [Revenge](https://www.codewars.com/kata/598a48baae35d17bc500001d) of [Hall Of Fame](https://www.codewars.com/kata/59879e52704c4f96540000c1)
>" *It should be good to **stay** in the Hall of Fame . . .* "

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

Stats:

CreatedSep 6, 2017
PublishedSep 6, 2017
Warriors Trained254
Total Skips9
Total Code Submissions1033
Total Times Completed99
JavaScript Completions99
Total Stars14
% of votes with a positive feedback rating94% of 42
Total "Very Satisfied" Votes37
Total "Somewhat Satisfied" Votes5
Total "Not Satisfied" Votes0
Total Rank Assessments8
Average Assessed Rank
5 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • ZozoFouchtra Avatar
  • aweleshetu Avatar
Ad