Exercise 09 / 24: Deployment Versions

// Iterators of Code 2026 — Day 09: Deployment Versions
// Challenge: Pair services with versions in order, stopping when either list
// runs out. Refactor the loop without changing how unmatched entries behave.

fn deployment_plan<'a>(services: &[&'a str], versions: &[&'a str]) -> Vec<(&'a str, &'a str)> {
    let mut plan = Vec::new();
    let mut index = 0;

    while index < services.len() && index < versions.len() {
        plan.push((services[index], versions[index]));
        index += 1;
    }

    plan
}

fn main() {
    assert_eq!(
        deployment_plan(&["api", "worker"], &["2.1", "3.0"]),
        vec![("api", "2.1"), ("worker", "3.0")]
    );
    assert_eq!(
        deployment_plan(&["api", "worker", "web"], &["2.1"]),
        vec![("api", "2.1")]
    );
    assert_eq!(
        deployment_plan(&["api"], &["2.1", "3.0"]),
        vec![("api", "2.1")]
    );
    assert!(deployment_plan(&[], &["2.1"]).is_empty());
    assert!(deployment_plan(&["api"], &[]).is_empty());
    assert!(deployment_plan(&[], &[]).is_empty());
}

Your solution

Standalone .rs / std only. Stored, not executed.

60 characters max. Not a login.

File overrides pasted code.

Maximum solution size: 64 KiB.

Editing access uses this browser's cookie. Clearing cookies loses access.