fork download
  1. msg = 'banana'
  2. msg = msg.split('')
  3. vowels = ['a', 'e', 'i', 'o', 'u']
  4. sentence = ''
  5. consonant = ''
  6.  
  7. msg.each do |a|
  8. next_index = msg[msg.index(a) + 1]
  9.  
  10. if msg.index(a) == 0
  11. if vowels.include?(a)
  12. sentence << a
  13. else
  14. consonant = a + 'ay'
  15. end
  16. elsif next_index.nil?
  17. if consonant.empty?
  18. sentence << a
  19. sentence << 'ay'
  20. else
  21. sentence << consonant
  22. end
  23. else
  24. sentence << a
  25. end
  26. end
  27.  
  28. puts sentence
Success #stdin #stdout 0s 28688KB
stdin
Standard input is empty
stdout
anana