diff --git a/exercises/clippy/clippy1.rs b/exercises/clippy/clippy1.rs index bdb5dd2c..eb712b28 100644 --- a/exercises/clippy/clippy1.rs +++ b/exercises/clippy/clippy1.rs @@ -6,12 +6,10 @@ // check clippy's suggestions from the output to solve the exercise. // Execute `rustlings hint clippy1` for hints :) -// I AM NOT DONE - fn main() { let x = 1.2331f64; let y = 1.2332f64; - if y != x { + if (x - y).abs() < 0.00001 { println!("Success!"); } } diff --git a/exercises/clippy/clippy2.rs b/exercises/clippy/clippy2.rs index 37af9ed0..4cdfbe75 100644 --- a/exercises/clippy/clippy2.rs +++ b/exercises/clippy/clippy2.rs @@ -1,12 +1,10 @@ // clippy2.rs // Make me compile! Execute `rustlings hint clippy2` for hints :) -// I AM NOT DONE - fn main() { let mut res = 42; let option = Some(12); - for x in option { + if let Some(x) = option { res += x; } println!("{}", res); diff --git a/exercises/standard_library_types/arc1.rs b/exercises/standard_library_types/arc1.rs index 9784e84a..f5e99bf1 100644 --- a/exercises/standard_library_types/arc1.rs +++ b/exercises/standard_library_types/arc1.rs @@ -4,17 +4,16 @@ // somewhere. Try not to create any copies of the `numbers` Vec! // Execute `rustlings hint arc1` for hints :) -// I AM NOT DONE - use std::sync::Arc; use std::thread; fn main() { let numbers: Vec<_> = (0..100u32).collect(); - let shared_numbers = // TODO + let shared_numbers = Arc::new(numbers); let mut joinhandles = Vec::new(); for offset in 0..8 { + let child_numbers = shared_numbers.clone(); joinhandles.push(thread::spawn(move || { let mut i = offset; let mut sum = 0; diff --git a/exercises/standard_library_types/iterators2.rs b/exercises/standard_library_types/iterators2.rs index 837725f0..d25fac89 100644 --- a/exercises/standard_library_types/iterators2.rs +++ b/exercises/standard_library_types/iterators2.rs @@ -7,16 +7,19 @@ // Try to ensure it returns a single string. // As always, there are hints if you execute `rustlings hint iterators2`! -// I AM NOT DONE - pub fn capitalize_first(input: &str) -> String { let mut c = input.chars(); match c.next() { None => String::new(), - Some(first) => first.collect::() + c.as_str(), + // TODO: Check why we would use collect() here? + Some(first) => first.to_uppercase().to_string() + c.as_str(), } } +pub fn capitalize_words(input: Vec<&str>) -> Vec { + input.iter().map(|word| capitalize_first(word)).collect::>() +} + #[cfg(test)] mod tests { use super::*; @@ -26,6 +29,7 @@ mod tests { #[test] fn test_success() { assert_eq!(capitalize_first("hello"), "Hello"); + assert_eq!(capitalize_first("é"), "É"); } #[test] @@ -37,14 +41,14 @@ mod tests { #[test] fn test_iterate_string_vec() { let words = vec!["hello", "world"]; - let capitalized_words: Vec = // TODO + let capitalized_words: Vec = capitalize_words(words); assert_eq!(capitalized_words, ["Hello", "World"]); } #[test] fn test_iterate_into_string() { let words = vec!["hello", " ", "world"]; - let capitalized_words = // TODO + let capitalized_words = capitalize_words(words).join(""); assert_eq!(capitalized_words, "Hello World"); } }