summaryrefslogtreecommitdiff
path: root/rustlings/exercises/05_vecs/vecs2.rs
diff options
context:
space:
mode:
authorHunter Kvalevog <hunter@kvog.sh>2026-10-02 21:53:51 -0500
committerHunter Kvalevog <hunter@kvog.sh>2026-10-02 21:53:51 -0500
commit4dfc11d74ab02ac5765ae5d08fb750c91f4744b4 (patch)
tree17ba62056d6b691dd0217b0e8f1b3a5826dce0f6 /rustlings/exercises/05_vecs/vecs2.rs
parent02d8f1c62896576e1266553a56980eddbc2a88d7 (diff)
rustlings: move to rust/
Diffstat (limited to 'rustlings/exercises/05_vecs/vecs2.rs')
-rw-r--r--rustlings/exercises/05_vecs/vecs2.rs61
1 files changed, 0 insertions, 61 deletions
diff --git a/rustlings/exercises/05_vecs/vecs2.rs b/rustlings/exercises/05_vecs/vecs2.rs
deleted file mode 100644
index 1ec77f7..0000000
--- a/rustlings/exercises/05_vecs/vecs2.rs
+++ /dev/null
@@ -1,61 +0,0 @@
-fn vec_loop(input: &[i32]) -> Vec<i32> {
- let mut output = Vec::new();
-
- for element in input {
- // TODO: Multiply each element in the `input` slice by 2 and push it to
- // the `output` vector.
- output.push(element * 2);
- }
-
- 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> {
- // TODO: Here, we also want to multiply each element in the `input` slice
- // by 2, but with iterator mapping instead of manually pushing into an empty
- // vector.
- // See the example in the function `vec_map_example` above.
- input
- .iter()
- .map(|element| {
- element * 2
- })
- .collect()
-}
-
-fn main() {
- // You can optionally experiment here.
-}
-
-#[cfg(test)]
-mod tests {
- use super::*;
-
- #[test]
- fn test_vec_loop() {
- let input = [2, 4, 6, 8, 10];
- 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]);
- }
-}