feat: add is_anagram to dsa

This commit is contained in:
rzmk 2024-03-05 15:55:21 -05:00
parent 1f32820941
commit b46a066dfc
No known key found for this signature in database
4 changed files with 127 additions and 4 deletions

View file

@ -34,6 +34,36 @@ pub enum Dsa {
#[arg(short = 'r', long)]
raw: bool,
},
/// Returns true or false based on whether string a is an anagram of string b.
///
/// ## Example
///
/// ### Input
///
/// ```bash
/// lz dsa is-anagram marc cram
/// ```
///
/// ### Output
///
/// ```bash
/// "marc" is an anagram of "cram".
/// ```
///
/// ## Raw Output (use `-r` or `--raw`)
///
/// ```bash
/// true
/// ```
IsAnagram {
/// The first string to compare against.
a: String,
/// The second string to compare against.
b: String,
/// Whether or not to return the raw output.
#[arg(short = 'r', long)]
raw: bool,
},
}
pub fn match_dsa(function: Option<Dsa>) {
@ -50,6 +80,18 @@ pub fn match_dsa(function: Option<Dsa>) {
)
}
},
Some(Dsa::IsAnagram { a, b, raw }) => match raw {
true => println!("{:?}", is_anagram(a, b)),
false => {
let result = is_anagram(a.clone(), b.clone());
println!(
"{:?} {} an anagram of {:?}.",
a,
if result { "is" } else { "is not" },
b,
)
}
},
None => {
println!("Please provide a function to use.");
}