Created
July 12, 2020 18:07
-
-
Save ircnelson/16194e4751f9e1f51d2eb59f7484b820 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub fn raindrops(n: u32) -> String { | |
let mut result = String::new(); | |
if let Some(v) = is_factor_of_three(n) { | |
result.push_str(v); | |
} | |
if let Some(v) = is_factor_of_five(n) { | |
result.push_str(v); | |
} | |
if let Some(v) = is_factor_of_seven(n) { | |
result.push_str(v); | |
} | |
if result.is_empty() { | |
result.push_str(&n.to_string()) | |
} | |
return result; | |
} | |
fn is_factor_of_three<'a>(n: u32) -> Option<&'a str> { | |
if n % 3 == 0 { | |
return Some("Pling"); | |
} | |
return None; | |
} | |
fn is_factor_of_five<'a>(n: u32) -> Option<&'a str> { | |
if n % 5 == 0 { | |
return Some("Plang"); | |
} | |
return None; | |
} | |
fn is_factor_of_seven<'a>(n: u32) -> Option<&'a str> { | |
if n % 7 == 0 { | |
return Some("Plong"); | |
} | |
return None; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment