add solutions

This commit is contained in:
mmo 2022-08-26 12:01:03 +02:00
parent a40913fcd4
commit f61b3a9e90
6 changed files with 11 additions and 14 deletions

View File

@ -11,11 +11,8 @@ pub fn bigger(a: i32, b: i32) -> i32 {
if a > b {
a
}
else if b > a {
b
}
else {
a
b
}
}

View File

@ -2,10 +2,9 @@
// Create an array with at least 100 elements in it where the ??? is.
// Execute `rustlings hint primitive_types3` or use the `hint` watch subcommand for a hint.
// I AM NOT DONE
fn main() {
let a = ???
let a = [0;100];
if a.len() >= 100 {
println!("Wow, that's a big array!");

View File

@ -2,13 +2,12 @@
// Get a slice out of Array a where the ??? is so that the test passes.
// Execute `rustlings hint primitive_types4` or use the `hint` watch subcommand for a hint.
// I AM NOT DONE
#[test]
fn slice_out_of_array() {
let a = [1, 2, 3, 4, 5];
let nice_slice = ???
let nice_slice = &a[1..4];
assert_eq!([2, 3, 4], nice_slice)
}

View File

@ -2,11 +2,10 @@
// Destructure the `cat` tuple so that the println will work.
// Execute `rustlings hint primitive_types5` or use the `hint` watch subcommand for a hint.
// I AM NOT DONE
fn main() {
let cat = ("Furry McFurson", 3.5);
let /* your pattern here */ = cat;
let (name, age) = cat;
println!("{} is {} years old.", name, age);
}

View File

@ -3,13 +3,12 @@
// You can put the expression for the second element where ??? is so that the test passes.
// Execute `rustlings hint primitive_types6` or use the `hint` watch subcommand for a hint.
// I AM NOT DONE
#[test]
fn indexing_tuple() {
let numbers = (1, 2, 3);
// Replace below ??? with the tuple indexing syntax.
let second = ???;
let second = numbers.1;
assert_eq!(2, second,
"This is not the 2nd number in the tuple!")

View File

@ -4,11 +4,15 @@
// Make me compile and pass the test!
// Execute `rustlings hint vecs1` or use the `hint` watch subcommand for a hint.
// I AM NOT DONE
fn array_and_vec() -> ([i32; 4], Vec<i32>) {
let a = [10, 20, 30, 40]; // a plain array
let v = // TODO: declare your vector here with the macro for vectors
let mut v = Vec::new();
for i in a {
v.push(i);
}
(a, v)
}