Menu
Coddy logo textTech

Recap - Username Builder

Part of the Logic & Flow section of Coddy's R journey. Lesson 6 of 64.

challenge icon

Challenge

Medium

Complete make_username(full_name, year) to build a username:

  1. Take the words of the name. The name may have extra spaces between or around the words.
  2. Use the first letter of the first word and the whole last word, in lower case.
  3. Remove every - and ' from the result.
  4. Add the last two digits of year.

For Ada Lovelace and 1815 the username is alovelace15. The function returns two lines: Username: followed by the username, and Length: followed by its number of characters.

The supplied code reads the name and the year and prints each returned line on its own line.

Try it yourself

make_username <- function(full_name, year) {
  # Write your code here
  c("Username: ", "Length: 0")
}

# Supplied input/output code: keep it as it is
input <- suppressWarnings(readLines(file("stdin")))
cat(make_username(input[1], input[2]), sep = "\n")

All lessons in Logic & Flow

Practice on your own: Online R compiler