diff --git a/src/pig_latin.rs b/src/pig_latin.rs index 66ca179..36f10d8 100644 --- a/src/pig_latin.rs +++ b/src/pig_latin.rs @@ -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; }