summaryrefslogtreecommitdiff
path: root/solutions
diff options
context:
space:
mode:
authorRemo Senekowitsch <remo@buenzli.dev>2025-09-24 20:56:58 +0200
committerRemo Senekowitsch <remo@buenzli.dev>2025-09-24 21:19:40 +0200
commitd8f4b06c91c54bccf934b84560641da3a7f202a8 (patch)
tree0238c533faca7d664b44456d1c92d83dfeeab5ce /solutions
parent2af9e89ba536fad01aa828b06e0ac2174bad0f6d (diff)
Remove use of `map` in early vecs2 exercise
Students do not have the necessary knowledge at this point to understand what's happening with the iterator combinators. This topic is covered well by the dedicated exercises about iterators later. closes #2102
Diffstat (limited to 'solutions')
-rw-r--r--solutions/05_vecs/vecs2.rs30
1 files changed, 0 insertions, 30 deletions
diff --git a/solutions/05_vecs/vecs2.rs b/solutions/05_vecs/vecs2.rs
index 87f7625..aae7103 100644
--- a/solutions/05_vecs/vecs2.rs
+++ b/solutions/05_vecs/vecs2.rs
@@ -8,22 +8,6 @@ fn vec_loop(input: &[i32]) -> Vec<i32> {
output
}
-fn vec_map_example(input: &[i32]) -> Vec<i32> {
- // An example of collecting a vector after mapping.
- // We map each element of the `input` slice to its value plus 1.
- // If the input is `[1, 2, 3]`, the output is `[2, 3, 4]`.
- input.iter().map(|element| element + 1).collect()
-}
-
-fn vec_map(input: &[i32]) -> Vec<i32> {
- // We will dive deeper into iterators, but for now, this is all what you
- // had to do!
- // Advanced note: This method is more efficient because it automatically
- // preallocates enough capacity. This can be done manually in `vec_loop`
- // using `Vec::with_capacity(input.len())` instead of `Vec::new()`.
- input.iter().map(|element| 2 * element).collect()
-}
-
fn main() {
// You can optionally experiment here.
}
@@ -38,18 +22,4 @@ mod tests {
let ans = vec_loop(&input);
assert_eq!(ans, [4, 8, 12, 16, 20]);
}
-
- #[test]
- fn test_vec_map_example() {
- let input = [1, 2, 3];
- let ans = vec_map_example(&input);
- assert_eq!(ans, [2, 3, 4]);
- }
-
- #[test]
- fn test_vec_map() {
- let input = [2, 4, 6, 8, 10];
- let ans = vec_map(&input);
- assert_eq!(ans, [4, 8, 12, 16, 20]);
- }
}