The Crew Directory
Stardate 55131.0 ยท UES Magnanimous
Briefing
Lt. Skree has confirmed the long-range contact is artificial, slow, and not responding to hails. The Captain has asked for every officer of a given rank to report to the bridge, and the crew directory has responded by listing everyone, which is not what he asked and is also, in the Chief's words, "just the crew".
The directory holds each person as a name and a rank. Given a rank, it should return the names of everyone holding it, in the order they appear in the directory. That is the whole request. The Captain has been told it will take five minutes and is standing behind you.
Mission objectives
ARCHIE checks all five every time you run diagnostics.
- โขEveryone of one rank, in directory order
- โขA rank held by exactly one person
- โขA rank held by nobody: an empty result
- โขNames are returned, not the whole records
- โขAn empty directory
Objective
Write find_by_rank(crew, rank): crew is a list of
(name, rank) tuples. Return a list of the names whose rank equals
rank, in the order they appear.
Press Run Diagnostics and I will tell you which objectives you actually met.
Objective
Write find_by_rank(crew: &[(&str, &str)], rank: &str) ->
Vec<String>: each record is (name, rank). Return the
names whose rank equals rank, in the order they appear.
Press Run Diagnostics and I will tell you which objectives you actually met.
Ask Commander Raghunathan for a hint
Loop over the records, and for each one whose rank matches, keep the name. In Python that is a comprehension with a condition; in Rust, filter then map.
Debrief
Four lieutenants on the bridge, in directory order. The Captain has thanked you and then asked whether the directory could also tell him who is on shift, which it cannot, and which he has written down for later.