public/subjects/pig_latin/README.md

55 lines
1.2 KiB
Markdown
Raw Permalink Normal View History

2020-12-29 10:40:42 +00:00
## pig_latin
### Instructions
2022-05-31 02:32:21 +00:00
Create a **function** which transforms the string passed as an argument into Pig Latin:
2020-12-29 10:40:42 +00:00
- If a word begins with a vowel, just add "ay" to the end.
2022-05-31 02:32:21 +00:00
- If it begins with a consonant, then we take all consonants before the first vowel, move them to the end of the word, and then add "ay" at the end.
2020-12-29 10:40:42 +00:00
- 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.
2022-10-17 17:08:03 +00:00
- Only the latin vowels will be considered as vowels (aeiou).
2020-12-29 10:40:42 +00:00
### Expected functions
```rust
2021-03-16 01:56:54 +00:00
pub fn pig_latin(text: &str) -> String {
}
2020-12-29 10:40:42 +00:00
```
### Usage
Here is a program to test your function.
```rust
2021-03-16 01:56:54 +00:00
use pig_latin::*;
2020-12-29 14:38:26 +00:00
2020-12-29 10:40:42 +00:00
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")));
println!("{}", pig_latin(&String::from("queen")));
2020-12-29 10:40:42 +00:00
}
```
2021-03-16 01:56:54 +00:00
And its output:
2020-12-29 10:40:42 +00:00
```console
$ cargo run
2020-12-29 10:40:42 +00:00
iglooay
appleay
ellohay
aresquay
enonxay
airchay
ueenqay
$
2020-12-29 10:40:42 +00:00
```
2022-05-31 02:32:21 +00:00
### Notions
- [patterns](https://doc.rust-lang.org/book/ch18-00-patterns.html)