Ejercicios 71/94

This commit is contained in:
perro tuerto 2023-02-28 10:45:05 -08:00
parent ddcbe65713
commit b6f879f07e
8 changed files with 15 additions and 31 deletions

View File

@ -8,17 +8,15 @@
//
// Execute `rustlings hint iterators1` or use the `hint` watch subcommand for a hint.
// I AM NOT DONE
fn main () {
let my_fav_fruits = vec!["banana", "custard apple", "avocado", "peach", "raspberry"];
let mut my_iterable_fav_fruits = ???; // TODO: Step 1
let mut my_iterable_fav_fruits = my_fav_fruits.iter(); // TODO: Step 1
assert_eq!(my_iterable_fav_fruits.next(), Some(&"banana"));
assert_eq!(my_iterable_fav_fruits.next(), ???); // TODO: Step 2
assert_eq!(my_iterable_fav_fruits.next(), Some(&"custard apple")); // TODO: Step 2
assert_eq!(my_iterable_fav_fruits.next(), Some(&"avocado"));
assert_eq!(my_iterable_fav_fruits.next(), ???); // TODO: Step 3
assert_eq!(my_iterable_fav_fruits.next(), Some(&"peach")); // TODO: Step 3
assert_eq!(my_iterable_fav_fruits.next(), Some(&"raspberry"));
assert_eq!(my_iterable_fav_fruits.next(), ???); // TODO: Step 4
assert_eq!(my_iterable_fav_fruits.next(), None); // TODO: Step 4
}

View File

@ -12,7 +12,7 @@ pub fn capitalize_first(input: &str) -> String {
let mut c = input.chars();
match c.next() {
None => String::new(),
Some(first) => ???,
Some(first) => format!("{}{}", first.to_uppercase(), c.as_str()),
}
}

View File

@ -7,9 +7,7 @@
//
// Execute `rustlings hint lifetimes1` or use the `hint` watch subcommand for a hint.
// I AM NOT DONE
fn longest(x: &str, y: &str) -> &str {
fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
if x.len() > y.len() {
x
} else {

View File

@ -6,8 +6,6 @@
//
// Execute `rustlings hint lifetimes2` or use the `hint` watch subcommand for a hint.
// I AM NOT DONE
fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
if x.len() > y.len() {
x
@ -19,9 +17,7 @@ fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
fn main() {
let string1 = String::from("long string is long");
let result;
{
let string2 = String::from("xyz");
result = longest(string1.as_str(), string2.as_str());
}
let string2 = String::from("xyz");
result = longest(string1.as_str(), string2.as_str());
println!("The longest string is '{}'", result);
}

View File

@ -4,11 +4,9 @@
//
// Execute `rustlings hint lifetimes3` or use the `hint` watch subcommand for a hint.
// I AM NOT DONE
struct Book {
author: &str,
title: &str,
struct Book<'a> {
author: &'a str,
title: &'a str,
}
fn main() {

View File

@ -7,12 +7,10 @@
// pass! Make the test fail!
// Execute `rustlings hint tests1` or use the `hint` watch subcommand for a hint.
// I AM NOT DONE
#[cfg(test)]
mod tests {
#[test]
fn you_can_assert() {
assert!();
assert!(true);
}
}

View File

@ -3,12 +3,10 @@
// pass! Make the test fail!
// Execute `rustlings hint tests2` or use the `hint` watch subcommand for a hint.
// I AM NOT DONE
#[cfg(test)]
mod tests {
#[test]
fn you_can_assert_eq() {
assert_eq!();
assert_eq!(1 + 1, 2);
}
}

View File

@ -4,8 +4,6 @@
// we expect to get when we call `is_even(5)`.
// Execute `rustlings hint tests3` or use the `hint` watch subcommand for a hint.
// I AM NOT DONE
pub fn is_even(num: i32) -> bool {
num % 2 == 0
}
@ -16,11 +14,11 @@ mod tests {
#[test]
fn is_true_when_even() {
assert!();
assert!(is_even(4));
}
#[test]
fn is_false_when_odd() {
assert!();
assert!(!is_even(5));
}
}