Skip to content

Commit

Permalink
vec exercises
Browse files Browse the repository at this point in the history
  • Loading branch information
rganesan committed May 15, 2024
1 parent 1bf1f9a commit 6a58e13
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
4 changes: 1 addition & 3 deletions exercises/05_vecs/vecs1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
//
// 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 v = vec![10, 20, 30, 40];

(a, v)
}
Expand Down
8 changes: 2 additions & 6 deletions exercises/05_vecs/vecs2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@
//
// Execute `rustlings hint vecs2` or use the `hint` watch subcommand for a hint.

// I AM NOT DONE

fn vec_loop(mut v: Vec<i32>) -> Vec<i32> {
for element in v.iter_mut() {
// TODO: Fill this up so that each element in the Vec `v` is
// multiplied by 2.
???
*element *= 2;
}

// At this point, `v` should be equal to [4, 8, 12, 16, 20].
Expand All @@ -24,7 +20,7 @@ fn vec_map(v: &Vec<i32>) -> Vec<i32> {
v.iter().map(|element| {
// TODO: Do the same thing as above - but instead of mutating the
// Vec, you can just return the new number!
???
element * 2
}).collect()
}

Expand Down

0 comments on commit 6a58e13

Please sign in to comment.