Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. pub fn convert(word: impl AsRef<str>) -> String {
  2. let word = word.as_ref();
  3.  
  4. let mut first_consonant = None;
  5.  
  6. let prefix: String = word.chars().enumerate().filter_map(|(i, c)|{
  7. if i == 0 && !"aeiou".contains(c) {
  8. first_consonant = Some(c);
  9. None
  10. } else {
  11. Some(c)
  12. }
  13. }).collect();
  14.  
  15. format!("{}-{}ay", prefix, first_consonant.unwrap_or('h'))
  16. }
  17.  
  18. fn main() {
  19. println!("{} {}", convert("apple"), convert("banana"));
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement