Krishna Kumar 61368257be
Improve vecs2 comments for beginners
#2221
Simplified TODO comment and added hint for beginners.
2026-03-29 11:48:20 +05:30

28 lines
561 B
Rust

fn vec_loop(input: &[i32]) -> Vec<i32> {
let mut output = Vec::new();
for element in input {
// TODO: Loop through each number in `input`,
// multiply it by 2, and add it to the `output` vector.
// Hint: Use a `for` loop and the `push` method.
}
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]);
}
}