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

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -