@@ -8,22 +8,6 @@ fn vec_loop(input: &[i32]) -> Vec<i32> {
88 output
99}
1010
11- fn vec_map_example ( input : & [ i32 ] ) -> Vec < i32 > {
12- // An example of collecting a vector after mapping.
13- // We map each element of the `input` slice to its value plus 1.
14- // If the input is `[1, 2, 3]`, the output is `[2, 3, 4]`.
15- input. iter ( ) . map ( |element| element + 1 ) . collect ( )
16- }
17-
18- fn vec_map ( input : & [ i32 ] ) -> Vec < i32 > {
19- // We will dive deeper into iterators, but for now, this is all what you
20- // had to do!
21- // Advanced note: This method is more efficient because it automatically
22- // preallocates enough capacity. This can be done manually in `vec_loop`
23- // using `Vec::with_capacity(input.len())` instead of `Vec::new()`.
24- input. iter ( ) . map ( |element| 2 * element) . collect ( )
25- }
26-
2711fn main ( ) {
2812 // You can optionally experiment here.
2913}
@@ -38,18 +22,4 @@ mod tests {
3822 let ans = vec_loop ( & input) ;
3923 assert_eq ! ( ans, [ 4 , 8 , 12 , 16 , 20 ] ) ;
4024 }
41-
42- #[ test]
43- fn test_vec_map_example ( ) {
44- let input = [ 1 , 2 , 3 ] ;
45- let ans = vec_map_example ( & input) ;
46- assert_eq ! ( ans, [ 2 , 3 , 4 ] ) ;
47- }
48-
49- #[ test]
50- fn test_vec_map ( ) {
51- let input = [ 2 , 4 , 6 , 8 , 10 ] ;
52- let ans = vec_map ( & input) ;
53- assert_eq ! ( ans, [ 4 , 8 , 12 , 16 , 20 ] ) ;
54- }
5525}
0 commit comments