From 14d63e2b8e2eaf9c1610a6b5d66d0cfcceb49e7a Mon Sep 17 00:00:00 2001 From: blacktoast Date: Tue, 12 Oct 2021 08:13:51 +0000 Subject: [PATCH] vec done --- exercises/collections/vec1.rs | 3 +-- exercises/collections/vec2.rs | 7 +++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/exercises/collections/vec1.rs b/exercises/collections/vec1.rs index b144fb94..ddd39644 100644 --- a/exercises/collections/vec1.rs +++ b/exercises/collections/vec1.rs @@ -4,11 +4,10 @@ // Make me compile and pass the test! // Execute the command `rustlings hint vec1` if you need hints. -// 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/collections/vec2.rs b/exercises/collections/vec2.rs index 6595e401..c88ff4b9 100644 --- a/exercises/collections/vec2.rs +++ b/exercises/collections/vec2.rs @@ -7,10 +7,13 @@ // Execute the command `rustlings hint vec2` if you need // hints. -// I AM NOT DONE fn vec_loop(mut v: Vec) -> Vec { for i in v.iter_mut() { + println!("{}",i); + *i=*i*2; + println!("{}",i); + // TODO: Fill this up so that each element in the Vec `v` is // multiplied by 2. } @@ -26,8 +29,8 @@ mod tests { #[test] fn test_vec_loop() { let v: Vec = (1..).filter(|x| x % 2 == 0).take(5).collect(); + let v2:Vec=(1..13).collect(); let ans = vec_loop(v.clone()); - assert_eq!(ans, v.iter().map(|x| x * 2).collect::>()); } }