Permalink
Browse files

Changed implementation to use map/join instead on inject.

  • Loading branch information...
1 parent 55a2900 commit c73dcff6abc93c938067a453a2cfe141123272e9 @robinroestenburg committed Apr 12, 2012
Showing with 1 addition and 6 deletions.
  1. +1 −6 morsecode/morse.rb
View
@@ -1,11 +1,6 @@
def morse_to_eng(morse)
morse_alphabet = Hash[%w(.- -... -.-. -.. . ..-. --. .... .. .--- -.- .-.. -- -. --- .--. --.- .-. ... - ..- ...- .-- -..- -.-- --..).zip 'A'..'Z']
- morse.split(/\s{3}/).inject("") do |translation, morse_word|
- morse_word.split(/\s/).inject(translation) do |translation, morse_code|
- translation << morse_alphabet[morse_code]
- end
- translation << " "
- end.strip
+ morse.split(/\s{3}/).map { |morse_word| morse_word.split(/\s/).map { |morse_code| morse_alphabet[morse_code] }.join }.join(" ")
end
describe 'morse_to_eng(morse)' do

0 comments on commit c73dcff

Please sign in to comment.