Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extern crate unicode_segmentation;
- use unicode_segmentation::UnicodeSegmentation;
- fn pig_latin2(s: &str) -> String {
- let vowels = ["a", "e", "i", "o", "u"];
- let g = UnicodeSegmentation::graphemes(s, true).collect::<Vec<&str>>();
- if vowels.contains(&g[0]) {
- format!("{}{}", s, "-hay")
- } else {
- format!("{}{}{}{}", &s[1..], "-", &s[0..1], "ay")
- }
- }
- fn pig_latin(s: &str) -> String {
- let first_letter = &s[0..1];
- let vowel_pig = format!("{}{}", s, "-hay");
- match first_letter {
- "a" => vowel_pig,
- "e" => vowel_pig,
- "i" => vowel_pig,
- "o" => vowel_pig,
- "u" => vowel_pig,
- _ => format!("{}{}{}{}", &s[1..], "-", first_letter, "ay"),
- }
- }
- fn main() {
- println!("{}", pig_latin("first"));
- println!("{}", pig_latin("apple"));
- println!("{}", pig_latin2("first"));
- println!("{}", pig_latin2("apple"));
- }
Add Comment
Please, Sign In to add comment