diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-07-15 10:42:21 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-15 10:42:21 +0100 |
| commit | 2fde156973e49f23a262ef454aa4f4e6031cfc98 (patch) | |
| tree | f615ac1af467694c7667c267f0bbacd4df8d5a53 | |
| parent | 01e229bca5c4464bdcd405d12ea8e7a412ac88ee (diff) | |
| parent | 53498476b2c285ac4bed7152f1f03680f34c81ea (diff) | |
| download | perlweeklychallenge-club-2fde156973e49f23a262ef454aa4f4e6031cfc98.tar.gz perlweeklychallenge-club-2fde156973e49f23a262ef454aa4f4e6031cfc98.tar.bz2 perlweeklychallenge-club-2fde156973e49f23a262ef454aa4f4e6031cfc98.zip | |
Merge pull request #12340 from fer2o3/kachow
feat(330): completed both challenges
| -rwxr-xr-x | challenge-330/benjamin-andre/rust/ch-1.rs | 26 | ||||
| -rwxr-xr-x | challenge-330/benjamin-andre/rust/ch-2.rs | 28 |
2 files changed, 54 insertions, 0 deletions
diff --git a/challenge-330/benjamin-andre/rust/ch-1.rs b/challenge-330/benjamin-andre/rust/ch-1.rs new file mode 100755 index 0000000000..cb3ebb5d96 --- /dev/null +++ b/challenge-330/benjamin-andre/rust/ch-1.rs @@ -0,0 +1,26 @@ +#!/bin/sh +//usr/bin/env rustc --test $0 -o kachow && ./kachow --nocapture; rm -f kachow ; exit + +fn clear_digits(s: &str) -> String { + let mut chars: Vec<char> = s.chars().collect(); + let mut i = 0; + while i < chars.len() { + if chars[i].is_ascii_digit() { + chars.remove(i); + if i > 0 { + chars.remove(i - 1); + i -= 1; + } + } else { + i += 1; + } + } + chars.into_iter().collect() +} + +#[test] +fn example() { + assert_eq!(clear_digits("cab12"), "c"); + assert_eq!(clear_digits("xy99"), ""); + assert_eq!(clear_digits("pa1erl"), "perl"); +} diff --git a/challenge-330/benjamin-andre/rust/ch-2.rs b/challenge-330/benjamin-andre/rust/ch-2.rs new file mode 100755 index 0000000000..b11fef1d9b --- /dev/null +++ b/challenge-330/benjamin-andre/rust/ch-2.rs @@ -0,0 +1,28 @@ +#!/bin/sh +//usr/bin/env rustc --test $0 -o kachow && ./kachow --nocapture; rm -f kachow ; exit + +fn title_capital(s: &str) -> String { + s.split_whitespace() + .map(|word| { + if word.len() <= 2 { + word.to_lowercase() + } else { + let lower = word.to_lowercase(); + let mut chars = lower.chars(); + chars.next().unwrap().to_uppercase().collect::<String>() + + &chars.collect::<String>() + } + }) + .collect::<Vec<_>>() + .join(" ") +} + +#[test] +fn example() { + assert_eq!(title_capital("PERL IS gREAT"), "Perl is Great"); + assert_eq!( + title_capital("THE weekly challenge"), + "The Weekly Challenge" + ); + assert_eq!(title_capital("YoU ARE A stAR"), "You Are a Star"); +} |
