Skip to content

Commit 6ae6c85

Browse files
committed
update
1 parent 640fd0a commit 6ae6c85

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

exercises/iterators/iterators1.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@
99
// Execute `rustlings hint iterators1` or use the `hint` watch subcommand for a
1010
// hint.
1111

12-
// I AM NOT DONE
12+
1313

1414
fn main() {
1515
let my_fav_fruits = vec!["banana", "custard apple", "avocado", "peach", "raspberry"];
1616

17-
let mut my_iterable_fav_fruits = ???; // TODO: Step 1
17+
let mut my_iterable_fav_fruits = my_fav_fruits.iter(); // TODO: Step 1
1818

1919
assert_eq!(my_iterable_fav_fruits.next(), Some(&"banana"));
20-
assert_eq!(my_iterable_fav_fruits.next(), ???); // TODO: Step 2
20+
assert_eq!(my_iterable_fav_fruits.next(), Some(&"custard apple")); // TODO: Step 2
2121
assert_eq!(my_iterable_fav_fruits.next(), Some(&"avocado"));
22-
assert_eq!(my_iterable_fav_fruits.next(), ???); // TODO: Step 3
22+
assert_eq!(my_iterable_fav_fruits.next(), Some(&"peach")); // TODO: Step 3
2323
assert_eq!(my_iterable_fav_fruits.next(), Some(&"raspberry"));
24-
assert_eq!(my_iterable_fav_fruits.next(), ???); // TODO: Step 4
24+
assert_eq!(my_iterable_fav_fruits.next(), None); // TODO: Step 4
2525
}

exercises/iterators/iterators2.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// Execute `rustlings hint iterators2` or use the `hint` watch subcommand for a
77
// hint.
88

9-
// I AM NOT DONE
9+
1010

1111
// Step 1.
1212
// Complete the `capitalize_first` function.
@@ -15,7 +15,7 @@ pub fn capitalize_first(input: &str) -> String {
1515
let mut c = input.chars();
1616
match c.next() {
1717
None => String::new(),
18-
Some(first) => ???,
18+
Some(first) => first.to_ascii_uppercase().to_string() + c.as_str(),
1919
}
2020
}
2121

@@ -24,15 +24,21 @@ pub fn capitalize_first(input: &str) -> String {
2424
// Return a vector of strings.
2525
// ["hello", "world"] -> ["Hello", "World"]
2626
pub fn capitalize_words_vector(words: &[&str]) -> Vec<String> {
27-
vec![]
27+
words.iter().map(|x| capitalize_first(x)).collect()
2828
}
2929

3030
// Step 3.
3131
// Apply the `capitalize_first` function again to a slice of string slices.
3232
// Return a single string.
3333
// ["hello", " ", "world"] -> "Hello World"
3434
pub fn capitalize_words_string(words: &[&str]) -> String {
35-
String::new()
35+
let mut ans: String = String::new();
36+
let words_iter = words.iter();
37+
for word in words_iter{
38+
ans = ans + &capitalize_first(word);
39+
}
40+
ans
41+
3642
}
3743

3844
#[cfg(test)]

exercises/tests/tests4.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Execute `rustlings hint tests4` or use the `hint` watch subcommand for a
66
// hint.
77

8-
// I AM NOT DONE
8+
99

1010
struct Rectangle {
1111
width: i32,
@@ -30,17 +30,19 @@ mod tests {
3030
fn correct_width_and_height() {
3131
// This test should check if the rectangle is the size that we pass into its constructor
3232
let rect = Rectangle::new(10, 20);
33-
assert_eq!(???, 10); // check width
34-
assert_eq!(???, 20); // check height
33+
assert_eq!(rect.width, 10); // check width
34+
assert_eq!(rect.height, 20); // check height
3535
}
3636

3737
#[test]
38+
#[should_panic]
3839
fn negative_width() {
3940
// This test should check if program panics when we try to create rectangle with negative width
4041
let _rect = Rectangle::new(-10, 10);
4142
}
4243

4344
#[test]
45+
#[should_panic]
4446
fn negative_height() {
4547
// This test should check if program panics when we try to create rectangle with negative height
4648
let _rect = Rectangle::new(10, -10);

0 commit comments

Comments
 (0)