-
Code fn disemvowel(string: &str) -> String { string.replace(['A','E','I','O','U','a','e','i','o','u'], "") }
Test Cases mod tests { use super::disemvowel; use rand::Rng; fn do_test(string: &str, expected: &str) { assert_eq!(disemvowel(string), expected); } fn test() { do_test("HI GUYS", "H GYS"); do_test("AEIOU", ""); do_test("Shrek is an orge", "Shrk s n rg"); } fn random_tests() { for _ in 0..100 { let string = (0..rand::thread_rng().gen_range(0..20)) .map(|_| rand::Rng::sample(&mut rand::thread_rng(), rand::distributions::Alphanumeric) as char) .collect::<String>(); let expected = string.chars().filter(|&c| !"AEIOUaeiou".contains(c)).collect::<String>(); do_test(&string, &expected); } } }
Output:
-
Code - fn disemvowel(string: &str) -> String {
string.chars().filter(|&c| !"AEIOUaeiou".contains(c)).collect()- string.replace(['A','E','I','O','U','a','e','i','o','u'], "")
- }
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
Please sign in or sign up to leave a comment.