SHARE
TWEET

Untitled

a guest Feb 20th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top