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
use std::convert::TryInto; | |
use chrono::prelude::*; // 0.4.11 | |
pub struct Mondays {} | |
impl Mondays { | |
pub fn count(birth: chrono::NaiveDate, curr_date: chrono::NaiveDate) -> i64 { | |
// start work at age 22 | |
let start_work = birth + chrono::Duration::days(22 * 365); | |
// retire at age 78 |
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
// https://dev.to/thepracticaldev/daily-challenge-29-xs-and-os-12mj | |
pub fn xo (value: &str) -> bool { | |
let value = value.to_lowercase(); | |
let count_x = value.matches("x").count(); | |
let count_o = value.matches("o").count(); | |
count_x == count_o | |
} | |
#[cfg(test)] |
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 ccbreaker (value: &str) -> String { | |
value.chars() | |
.into_iter() | |
.map(|c| if c.is_uppercase() { format!(" {}", c.to_lowercase()) } else { c.to_string() }) | |
.collect::<String>() | |
} | |
#[cfg(test)] | |
mod tests { | |
use super::*; |
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
// Convert number to hex string. | |
pub fn to_hex (value: i32) -> String { | |
let value = if value > 255 { 255 } else if value < 0 { 0 } else { value }; | |
format!("{:02X}", value) | |
} | |
// Join all hex strings together from rgb input. | |
pub fn rgb (r: i32, g: i32, b: i32) -> String { | |
format!("{}{}{}", to_hex(r), to_hex(g), to_hex(b)) | |
} |