Ejercicios 71/94
This commit is contained in:
parent
ddcbe65713
commit
b6f879f07e
|
@ -8,17 +8,15 @@
|
||||||
//
|
//
|
||||||
// Execute `rustlings hint iterators1` or use the `hint` watch subcommand for a hint.
|
// Execute `rustlings hint iterators1` or use the `hint` watch subcommand for a hint.
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
fn main () {
|
fn main () {
|
||||||
let my_fav_fruits = vec!["banana", "custard apple", "avocado", "peach", "raspberry"];
|
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(), 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(), 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(), Some(&"raspberry"));
|
||||||
assert_eq!(my_iterable_fav_fruits.next(), ???); // TODO: Step 4
|
assert_eq!(my_iterable_fav_fruits.next(), None); // TODO: Step 4
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ pub fn capitalize_first(input: &str) -> String {
|
||||||
let mut c = input.chars();
|
let mut c = input.chars();
|
||||||
match c.next() {
|
match c.next() {
|
||||||
None => String::new(),
|
None => String::new(),
|
||||||
Some(first) => ???,
|
Some(first) => format!("{}{}", first.to_uppercase(), c.as_str()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,9 +7,7 @@
|
||||||
//
|
//
|
||||||
// Execute `rustlings hint lifetimes1` or use the `hint` watch subcommand for a hint.
|
// Execute `rustlings hint lifetimes1` or use the `hint` watch subcommand for a hint.
|
||||||
|
|
||||||
// I AM NOT DONE
|
fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
|
||||||
|
|
||||||
fn longest(x: &str, y: &str) -> &str {
|
|
||||||
if x.len() > y.len() {
|
if x.len() > y.len() {
|
||||||
x
|
x
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -6,8 +6,6 @@
|
||||||
//
|
//
|
||||||
// Execute `rustlings hint lifetimes2` or use the `hint` watch subcommand for a hint.
|
// 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 {
|
fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
|
||||||
if x.len() > y.len() {
|
if x.len() > y.len() {
|
||||||
x
|
x
|
||||||
|
@ -19,9 +17,7 @@ fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
|
||||||
fn main() {
|
fn main() {
|
||||||
let string1 = String::from("long string is long");
|
let string1 = String::from("long string is long");
|
||||||
let result;
|
let result;
|
||||||
{
|
let string2 = String::from("xyz");
|
||||||
let string2 = String::from("xyz");
|
result = longest(string1.as_str(), string2.as_str());
|
||||||
result = longest(string1.as_str(), string2.as_str());
|
|
||||||
}
|
|
||||||
println!("The longest string is '{}'", result);
|
println!("The longest string is '{}'", result);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,11 +4,9 @@
|
||||||
//
|
//
|
||||||
// Execute `rustlings hint lifetimes3` or use the `hint` watch subcommand for a hint.
|
// Execute `rustlings hint lifetimes3` or use the `hint` watch subcommand for a hint.
|
||||||
|
|
||||||
// I AM NOT DONE
|
struct Book<'a> {
|
||||||
|
author: &'a str,
|
||||||
struct Book {
|
title: &'a str,
|
||||||
author: &str,
|
|
||||||
title: &str,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
|
@ -7,12 +7,10 @@
|
||||||
// pass! Make the test fail!
|
// pass! Make the test fail!
|
||||||
// Execute `rustlings hint tests1` or use the `hint` watch subcommand for a hint.
|
// Execute `rustlings hint tests1` or use the `hint` watch subcommand for a hint.
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn you_can_assert() {
|
fn you_can_assert() {
|
||||||
assert!();
|
assert!(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,12 +3,10 @@
|
||||||
// pass! Make the test fail!
|
// pass! Make the test fail!
|
||||||
// Execute `rustlings hint tests2` or use the `hint` watch subcommand for a hint.
|
// Execute `rustlings hint tests2` or use the `hint` watch subcommand for a hint.
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn you_can_assert_eq() {
|
fn you_can_assert_eq() {
|
||||||
assert_eq!();
|
assert_eq!(1 + 1, 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,6 @@
|
||||||
// we expect to get when we call `is_even(5)`.
|
// we expect to get when we call `is_even(5)`.
|
||||||
// Execute `rustlings hint tests3` or use the `hint` watch subcommand for a hint.
|
// Execute `rustlings hint tests3` or use the `hint` watch subcommand for a hint.
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
pub fn is_even(num: i32) -> bool {
|
pub fn is_even(num: i32) -> bool {
|
||||||
num % 2 == 0
|
num % 2 == 0
|
||||||
}
|
}
|
||||||
|
@ -16,11 +14,11 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn is_true_when_even() {
|
fn is_true_when_even() {
|
||||||
assert!();
|
assert!(is_even(4));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn is_false_when_odd() {
|
fn is_false_when_odd() {
|
||||||
assert!();
|
assert!(!is_even(5));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue