From 29af744b2b82bdc88da01eee8d176bee191b9068 Mon Sep 17 00:00:00 2001 From: asif256000 Date: Fri, 23 Dec 2022 02:04:04 -0500 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=F0=9F=A6=80=20Vectors=20Solved?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- exercises/vecs/vecs1.rs | 4 +--- exercises/vecs/vecs2.rs | 16 ++++++++-------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/exercises/vecs/vecs1.rs b/exercises/vecs/vecs1.rs index 4e8c4cbb..0e8e2f73 100644 --- a/exercises/vecs/vecs1.rs +++ b/exercises/vecs/vecs1.rs @@ -4,11 +4,9 @@ // 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) { let a = [10, 20, 30, 40]; // a plain array - let v = // TODO: declare your vector here with the macro for vectors + let v = vec![10, 20, 30, 40]; // TODO: declare your vector here with the macro for vectors (a, v) } diff --git a/exercises/vecs/vecs2.rs b/exercises/vecs/vecs2.rs index 5bea09a2..673d6257 100644 --- a/exercises/vecs/vecs2.rs +++ b/exercises/vecs/vecs2.rs @@ -6,13 +6,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 i in v.iter_mut() { // TODO: Fill this up so that each element in the Vec `v` is // multiplied by 2. - ??? + *i *= 2; } // At this point, `v` should be equal to [4, 8, 12, 16, 20]. @@ -20,11 +18,13 @@ fn vec_loop(mut v: Vec) -> Vec { } fn vec_map(v: &Vec) -> Vec { - v.iter().map(|num| { - // TODO: Do the same thing as above - but instead of mutating the - // Vec, you can just return the new number! - ??? - }).collect() + v.iter() + .map(|num| { + // TODO: Do the same thing as above - but instead of mutating the + // Vec, you can just return the new number! + num * 2 + }) + .collect() } #[cfg(test)]