From 147c455b7d94847cda01daa4aac66b2adfcfac63 Mon Sep 17 00:00:00 2001 From: Daniil Moiseev Date: Wed, 21 Sep 2022 21:17:30 +0000 Subject: [PATCH] vec --- exercises/vecs/vecs1.rs | 10 ++++++---- exercises/vecs/vecs2.rs | 6 ++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/exercises/vecs/vecs1.rs b/exercises/vecs/vecs1.rs index 65b7a7f8..e993a1e4 100644 --- a/exercises/vecs/vecs1.rs +++ b/exercises/vecs/vecs1.rs @@ -7,12 +7,14 @@ // // Execute `rustlings hint vecs1` or use the `hint` watch subcommand for a hint. -// I AM NOT DONE - fn array_and_vec() -> ([i32; 4], Vec) { 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 = Vec::new(); // TODO: declare your vector here with the macro for vectors + // v.push(10); + // v.push(20); + // v.push(30); + // v.push(40); + let v = vec![10, 20, 30, 40]; (a, v) } diff --git a/exercises/vecs/vecs2.rs b/exercises/vecs/vecs2.rs index e92c970a..8433e132 100644 --- a/exercises/vecs/vecs2.rs +++ b/exercises/vecs/vecs2.rs @@ -7,13 +7,11 @@ // // Execute `rustlings hint vecs2` or use the `hint` watch subcommand for a hint. -// I AM NOT DONE - fn vec_loop(mut v: Vec) -> Vec { for element in v.iter_mut() { // TODO: Fill this up so that each element in the Vec `v` is // multiplied by 2. - ??? + *i = *i * 2 } // At this point, `v` should be equal to [4, 8, 12, 16, 20]. @@ -24,7 +22,7 @@ fn vec_map(v: &Vec) -> Vec { v.iter().map(|element| { // TODO: Do the same thing as above - but instead of mutating the // Vec, you can just return the new number! - ??? + num * 2 }).collect() }