ruby - Trying to concat 2 arrays that are output from the map method -
i'm doing 'morse code' exercise , running difficulty. i'll skip posting hash created stores code , letter.
the morse code in method call has 3 spaces between 'words' example -
decodemorse('.... . -.-- .--- ..- -.. .')
my strategy split words first using split(/\s\s\s/)
gives me separate arrays each word, arrays need split(' ')
letters.
this code -
sc = str.split(/\s\s\s/) sc.each |string| string.split(' ').map {|key| morsecode[key]; }
it works okay, i'm left 2 arrays @ end:
=> ["h", "e", "y"] => ["j", "u", "d", "e"]
normally, if had 2 or more arrays had assigned variable names know how concat them i've tried , searched on hasn't changed situation. join('') 2 words no space between them.
sc = str.split(/\s\s\s/) deciphered = sc.map |string| string.split(' ').map {|key| morsecode[key]; }.join end deciphered.join(' ')
Comments
Post a Comment