DEV Community

loading...

Discussion on: Daily Challenge #40 - Counting Sheep

Collapse
jay profile image
Jay

Rust solution: [Playground](

fn count_sheeps(num: u32) -> String {
    let sheep = "🐑"; 
    (1..=num)
        // .map(|n| format!("{} sheep...", n))
        .map(|n| format!("{}... ", sheep.repeat(n as usize)))
        .collect::<Vec<String>>()
        .join("")
}

// -> 🐑... 🐑🐑... 🐑🐑🐑...