Exercise 19 / 24: Task Labels
// Iterators of Code 2026 — Day 19: Task Labels
// Challenge: Replace the nested loops with one iterator pipeline.
// Expand each project's tasks into "project/task" labels in input order.
// Projects without tasks contribute nothing; repeated tasks stay repeated.
fn task_labels(projects: &[(&str, &[&str])]) -> Vec<String> {
let mut labels = Vec::new();
for (project, tasks) in projects {
for task in *tasks {
labels.push(format!("{project}/{task}"));
}
}
labels
}
fn main() {
let projects: &[(&str, &[&str])] = &[
("website", &["build", "deploy"]),
("archive", &[]),
("mobile", &["test"]),
];
assert_eq!(
task_labels(projects),
vec!["website/build", "website/deploy", "mobile/test"]
);
assert!(task_labels(&[]).is_empty());
assert!(task_labels(&[("archive", &[])]).is_empty());
assert_eq!(
task_labels(&[("api", &["test", "test"])]),
vec!["api/test", "api/test"]
);
}
Your solution
Standalone .rs / std only. Stored, not executed.
Editing access uses this browser's cookie. Clearing cookies loses access.