/
iterative.rs
39 lines (34 loc) · 1023 Bytes
/
iterative.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
pub struct Solution;
// ------------------------------------------------------ snip ------------------------------------------------------ //
impl Solution {
pub fn fizz_buzz(n: i32) -> Vec<String> {
(1..=n)
.map(|i| {
if i % 3 == 0 {
if i % 5 == 0 {
String::from("FizzBuzz")
} else {
String::from("Fizz")
}
} else if i % 5 == 0 {
String::from("Buzz")
} else {
i.to_string()
}
})
.collect()
}
}
// ------------------------------------------------------ snip ------------------------------------------------------ //
impl super::Solution for Solution {
fn fizz_buzz(n: i32) -> Vec<String> {
Self::fizz_buzz(n)
}
}
#[cfg(test)]
mod tests {
#[test]
fn test_solution() {
super::super::tests::run::<super::Solution>();
}
}