The Badge Printer
Stardate 55107.4 ยท UES Magnanimous
Briefing
There is a diplomatic reception on Thursday, and the badge printer has produced forty-one badges in exactly the case and spacing each crew member typed into the form. Three badges have leading spaces. One is entirely lower case. Ensign Tannenbaum's reads "bo!!!", and he has been asked not to do that again.
The Captain's badge says " yves ". He would like it to say "YVES", and he would like it before the ambassador arrives.
Mission objectives
ARCHIE checks all five every time you run diagnostics.
- โขLeading and trailing spaces removed
- โขLower case becomes upper case
- โขAlready-clean input passes through unchanged
- โขBoth problems at once
- โขSpaces inside the name are kept, only the ends are trimmed
Objective
Write badge(name): strip whitespace from both ends of name
and return it in upper case. Spaces inside the name are kept.
Press Run Diagnostics and I will tell you which objectives you actually met.
Objective
Write badge(name: &str) -> String: trim whitespace from both ends
and return the name in upper case. Spaces inside the name are kept.
Press Run Diagnostics and I will tell you which objectives you actually met.
Ask Commander Raghunathan for a hint
Two string methods, chained. One trims whitespace from the ends, one changes the case. The order does not matter here, but the third objective is worth reading twice: internal spaces stay.
Debrief
Forty-one badges, all in upper case, no stray spaces. Ensign Tannenbaum's now reads "BO!!!", which he says is "somehow worse", and which nobody has offered to fix.