Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions morse_code.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
HASH_MORSE = {
'.-' => 'a',
'-..' => 'b',
'-...' => 'b',
'-.-.' => 'c',
'-..' => 'd',
'.' => 'e',
Expand Down Expand Up @@ -33,7 +33,7 @@
'-....' => '6',
'--...' => '7',
'---..' => '8',
'----.' => '8',
'----.' => '9',
'-----' => '0',
'/' => ' ' # Mapping foward bar to be a space
}
Expand All @@ -45,7 +45,7 @@ def get_translated(string_morse)
end

def mk_morse_code line
line.split('').map{|c| HASH_MORSE.index c.downcase}.join(' ')
line.split('').map{|c| HASH_MORSE.key c.downcase}.join(' ')
end

private
Expand All @@ -66,4 +66,4 @@ def translate(string_morse)

mc = morse.mk_morse_code('HAHAHA Interesting! Thx PotHix.')
puts mc
morse.get_translated mc
morse.get_translated mc