← Back to challenges

Encode Morse

JavaScriptHardarraysconditionsloops

Instructions

Create a function that takes a string as an argument and returns the Morse code equivalent.

Examples

encodeMorse("EDABBIT CHALLENGE") ➞ ". -.. .- -... -... .. -   -.-. .... .- .-.. .-.. . -. --. ."

encodeMorse("HELP ME !") ➞ ".... . .-.. .--.   -- .   -.-.--"

Notes

  • Ouput should be International Morse Code, and use the standard conventions for symbols not defined inside the ITU recommendation.
  • Input value can be lower or upper case.
  • Input string can have digits.
  • Input string can have some special characters (e.g. comma, colon, apostrophe, period, question mark, exclamation mark).
  • One space " " is expected after each character, except the last one.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Lottery Ticket