This commit is contained in:
blacktoast 2021-10-12 08:13:51 +00:00
parent 8eb8525699
commit 14d63e2b8e
2 changed files with 6 additions and 4 deletions

View File

@ -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<i32>) {
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)
}

View File

@ -7,10 +7,13 @@
// Execute the command `rustlings hint vec2` if you need
// hints.
// I AM NOT DONE
fn vec_loop(mut v: Vec<i32>) -> Vec<i32> {
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<i32> = (1..).filter(|x| x % 2 == 0).take(5).collect();
let v2:Vec<i32>=(1..13).collect();
let ans = vec_loop(v.clone());
assert_eq!(ans, v.iter().map(|x| x * 2).collect::<Vec<i32>>());
}
}