mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-04 01:39:18 +00:00
Fix multiplication logic in vec_loop and vec_map functions
This commit is contained in:
parent
294c97b9fc
commit
51775de8dc
@ -6,14 +6,13 @@
|
||||
// Make me pass the test!
|
||||
//
|
||||
// Execute `rustlings hint vecs2` or use the `hint` watch subcommand for a hint.
|
||||
|
||||
// I AM NOT DONE
|
||||
// [[NOTE]] 解引用, map
|
||||
|
||||
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; // Fill this up so that each element in the Vec `v` is
|
||||
}
|
||||
|
||||
// At this point, `v` should be equal to [4, 8, 12, 16, 20].
|
||||
@ -22,10 +21,9 @@ fn vec_loop(mut v: Vec<i32>) -> Vec<i32> {
|
||||
|
||||
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!
|
||||
???
|
||||
}).collect()
|
||||
element * 2 // Do the same thing as above - but instead of mutating the
|
||||
}).collect::<Vec<i32>>()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user