It seems that you all liked part 1, so on to part 2! I'll be making a change to the format, though: the winner of the previous challenge gets posted here, and they have to reply to get their prize.
Code Golf Challenge 2 - Morse Code Translator
Quick recap of what Code Golf is on this forum: the challenge is to write a script, which, when entered in the CDO GameLab or AppLab console (that got a lot of you last time), will fulfill the requirements of whatever it is this time.
Which, this time, is an English to Morse Code translator.
This one will be different than last time: whereas the first challenge was to print out the same thing every time, you will have to write a function that takes 1 (one) parameter, which will always be composed of capital letters A-Z and 0-9, and a space (nothing else). The function has to put back into the console that text as Morse Code, meaning dots "." and dashes "-" (the space becomes a "/", and there are spaces between each pattern, as to avoid confusion with patterns). For example, "ABC 123" becomes .- -... -.-. / .---- ..--- ...--
, not the spaces. You can use this chart to see the codes. Again, all you need to write is a function: function(){ something }
, since CDO (ES5) doesn't allow for =>
. To evaluate it, I will assign that function to a variable, and then run it with a series of inputs.
Winner gets 100 coins! I might give out some extra if I see some creative answers like last time! Have fun!
Previous winner: @Varrience with 59 characters.
My current solution is embarassingly long (276). Please beat me, or I'll be disappointed...
Also, follow me to make sure you don't miss out on these! I'm not saying this as advertisement; if you're of the less active type on the forum and want to catch these, it could be a good idea to follow me.
Important
Following a lot of people asking this: you can't use external JS or data. Also, the script has to work in any CDO project's console, meaning that if I copy+paste it into some random project, it has to work.