Joining elements of a list into a string
The join()
method is used to join all elements of an array into a string. It takes an optional argument that specifies the separator to be used between the elements of the array. If no separator is provided, a comma is used as the default separator.
Splitting a string into an array
As we have seen in the previous section, the join()
method is used to join all elements of an array into a string. The split()
method is used to split a string into an array of substrings, and returns the new array. It takes an optional argument that specifies the separator to be used to separate the substrings.
Code Challenge
Morse Code
is a method used in telecommunication to encode text characters as standardized sequences of two different signal durations, called dots
and dashes
.
Ex: The letter A
in Morse code is represented by .-
, letter Q
is represented by --.-
, and digit 1
is represented by .----
. Each Morse code symbol is separated by a space
character.
You mission is to write a function that takes a string
with Morse code as input and returns a decoded human-readable string. Each letter must be separated by a -
character.
You will receive an object with the Morse code
as a key and the corresponding letter as a value. For example: { '.-': 'A', '-...': 'B', ... }
. All the test strings would contain valid Morse code, so you may skip checking for errors and exceptions.