Recap - Leaderboard
Part of the Logic & Flow section of Coddy's R journey. Lesson 41 of 64.
Challenge
MediumComplete leaderboard(names, points). Each entry records the points one player scored in one round, and a player can appear many times. Return one line per player, 1. ana 15 (2 rounds), ranked by total points from high to low. Players with the same total are ranked alphabetically.
Then add Best round: followed by the player and the points of the single highest entry, such as cy 12. When several entries share the highest points, use the first of them.
The supplied code reads the rounds as name:points pairs separated by commas and prints each returned line.
Try it yourself
leaderboard <- function(names, points) {
# Write your code here
character(0)
}
# Supplied input/output code: keep it as it is
input <- suppressWarnings(readLines(file("stdin")))
pairs <- strsplit(strsplit(input[1], ",")[[1]], ":")
names <- sapply(pairs, function(p) p[1])
values <- as.numeric(sapply(pairs, function(p) p[2]))
cat(leaderboard(names, values), sep = "\n")
All lessons in Logic & Flow
1Strings In Depth
Substrings with substr()Formatting with sprintf()Splitting and JoiningSearching StringsReplacing TextRecap - Username Builder4Matrices
Creating MatricesIndexing MatricesRow and Column SummariesMatrix ArithmeticRecap - Seating Chart2Key-Value Lookups
Named Vector LookupsChecking KeysAdding and Removing KeysLooping Over NamesRecap - Stock Desk8Sorting and Grouping
Sorting VectorsSorting by a KeyGrouping with split()Group SummariesRecap - Leaderboard3Sets and Counting
Unique ValuesSet OperationsMembership TestsCounting with table()Recap - Event Guests6Functions as Values
Anonymous FunctionsPassing FunctionsReturning FunctionsClosures with StateRecap - Discount Rules9Data Frames
Creating Data FramesColumns and RowsFiltering RowsAdding and SortingRecap - Sales Report12Project - Expense Tracker
Recording ExpensesTotal SpendingPractice on your own: Online R compiler