You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.2 KiB

## pig_latin
### Instructions
4 years ago
Write a **function** that transforms a string passed as argument in its `Pig Latin` version.
The rules used by Pig Latin are the following:
- If a word begins with a vowel, just add "ay" to the end.
4 years ago
- If it begins with a consonant, then we take all consonants before the first vowel and we put them at the end of the word and add "ay" at the end.
- If a word starts with a consonant followed by "qu", move it to the end of the word, and then add an "ay" at the end.
### Notions
4 years ago
- [patterns](https://doc.rust-lang.org/book/ch18-00-patterns.html)
### Expected functions
```rust
4 years ago
pub fn pig_latin(text: &str) -> String {
}
```
### Usage
Here is a program to test your function.
```rust
4 years ago
use pig_latin::*;
fn main() {
println!("{}", pig_latin(&String::from("igloo")));
println!("{}", pig_latin(&String::from("apple")));
println!("{}", pig_latin(&String::from("hello")));
println!("{}", pig_latin(&String::from("square")));
println!("{}", pig_latin(&String::from("xenon")));
println!("{}", pig_latin(&String::from("chair")));
}
```
4 years ago
And its output:
```console
student@ubuntu:~/pig_latin/test$ cargo run
iglooay
appleay
ellohay
aresquay
enonxay
airchay
student@ubuntu:~/pig_latin/test$
```