Merge branch 'exercises/pig-latin'
This commit is contained in:
@@ -1,16 +1,14 @@
|
||||
pub fn pig_latin(string: &str) -> String {
|
||||
// NOTE: does this need to be a String or can we use the &str passed in?
|
||||
let s = String::from(string);
|
||||
let mut portion = String::new();
|
||||
let mut latinised = String::new();
|
||||
let mut starts_with_vowel = false;
|
||||
let vowels = ['a', 'e', 'i', 'o', 'u'];
|
||||
|
||||
if s.is_empty() {
|
||||
return s;
|
||||
if string.is_empty() {
|
||||
return latinised;
|
||||
}
|
||||
|
||||
let first_character = s.chars().next().unwrap();
|
||||
let first_character = string.chars().next().unwrap();
|
||||
|
||||
if vowels.contains(&first_character) {
|
||||
portion.push_str("-hay");
|
||||
@@ -18,7 +16,7 @@ pub fn pig_latin(string: &str) -> String {
|
||||
} else {
|
||||
portion = format!("-{}ay", &first_character);
|
||||
}
|
||||
for (pos, char) in s.char_indices() {
|
||||
for (pos, char) in string.char_indices() {
|
||||
if pos == 0 && !starts_with_vowel {
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user