mirror of
https://github.com/rust-lang/rustlings.git
synced 2025-10-08 23:02:03 +02:00
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
26 lines
423 B
Rust
26 lines
423 B
Rust
fn vec_loop(input: &[i32]) -> Vec<i32> {
|
|
let mut output = Vec::new();
|
|
|
|
for element in input {
|
|
output.push(2 * element);
|
|
}
|
|
|
|
output
|
|
}
|
|
|
|
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]);
|
|
}
|
|
}
|