Browse files

Replaced zip-method by faster hash.

  • Loading branch information...
1 parent c73dcff commit 636f7aa3f54fb1c2096f743fdf52feb4de8251b8 @robinroestenburg committed Apr 12, 2012
Showing with 1 addition and 1 deletion.
  1. +1 −1 morsecode/morse.rb
View
2 morsecode/morse.rb
@@ -1,5 +1,5 @@
def morse_to_eng(morse)
- morse_alphabet = Hash[%w(.- -... -.-. -.. . ..-. --. .... .. .--- -.- .-.. -- -. --- .--. --.- .-. ... - ..- ...- .-- -..- -.-- --..).zip 'A'..'Z']
+ morse_alphabet = {'.-' => 'A', '-...' => 'B', '-.-.' => 'C', '-..' => 'D', '.' => 'E', '..-.' => 'F', '--.' => 'G', '....' => 'H', '..' => 'I', '.---' => 'J', '-.-' => 'K', '.-..' => 'L', '--' => 'M', '-.' => 'N', '---' => 'O', '.--.' => 'P', '--.-' => 'Q', '.-.' => 'R', '...' => 'S', '-' => 'T', '..-' => 'U', '...-' => 'V', '.--' => 'W', '-..-' => 'X', '-.--' => 'Y', '--..' => 'Z'}
morse.split(/\s{3}/).map { |morse_word| morse_word.split(/\s/).map { |morse_code| morse_alphabet[morse_code] }.join }.join(" ")
end

0 comments on commit 636f7aa

Please sign in to comment.