Created
May 30, 2019 19:41
-
-
Save ivanji/ad931bec137195013decfeedbfbcc430 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/sigudum
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width"> | |
| <title>JS Bin</title> | |
| </head> | |
| <body> | |
| <script id="jsbin-javascript"> | |
| const morseCode = { | |
| ".-": "a", | |
| "-...": "b", | |
| "-.-.": "c", | |
| "-..": "d", | |
| ".": "e", | |
| "..-.": "f", | |
| "--.": "g", | |
| "....": "h", | |
| "..": "i", | |
| ".---": "j", | |
| "-.-": "k", | |
| ".-..": "l", | |
| "--": "m", | |
| "-.": "n", | |
| "---": "o", | |
| ".--.": "p", | |
| "--.-": "q", | |
| ".-.": "r", | |
| "...": "s", | |
| "-": "t", | |
| "..-": "u", | |
| "...-": "v", | |
| ".--": "w", | |
| "-..-": "x", | |
| "-.--": "y", | |
| "--..": "z", | |
| "-----": "0", | |
| ".----": "1", | |
| "..---": "2", | |
| "...--": "3", | |
| "....-": "4", | |
| ".....": "5", | |
| "-....": "6", | |
| "--...": "7", | |
| "---..": "8", | |
| "----.": "9", | |
| "": " " | |
| } | |
| function decode(str) { | |
| console.log(str.split(" ")) | |
| // implement morse decode here | |
| return str.split(" ").reduce((result, word) => { | |
| result += morseCode[word] | |
| return result | |
| }, "") | |
| } | |
| console.log(decode(".... . .-.. .-.. --- .-- --- .-. .-.. -..")) | |
| </script> | |
| <script id="jsbin-source-javascript" type="text/javascript">const morseCode = { | |
| ".-": "a", | |
| "-...": "b", | |
| "-.-.": "c", | |
| "-..": "d", | |
| ".": "e", | |
| "..-.": "f", | |
| "--.": "g", | |
| "....": "h", | |
| "..": "i", | |
| ".---": "j", | |
| "-.-": "k", | |
| ".-..": "l", | |
| "--": "m", | |
| "-.": "n", | |
| "---": "o", | |
| ".--.": "p", | |
| "--.-": "q", | |
| ".-.": "r", | |
| "...": "s", | |
| "-": "t", | |
| "..-": "u", | |
| "...-": "v", | |
| ".--": "w", | |
| "-..-": "x", | |
| "-.--": "y", | |
| "--..": "z", | |
| "-----": "0", | |
| ".----": "1", | |
| "..---": "2", | |
| "...--": "3", | |
| "....-": "4", | |
| ".....": "5", | |
| "-....": "6", | |
| "--...": "7", | |
| "---..": "8", | |
| "----.": "9", | |
| "": " " | |
| } | |
| function decode(str) { | |
| console.log(str.split(" ")) | |
| // implement morse decode here | |
| return str.split(" ").reduce((result, word) => { | |
| result += morseCode[word] | |
| return result | |
| }, "") | |
| } | |
| console.log(decode(".... . .-.. .-.. --- .-- --- .-. .-.. -.."))</script></body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const morseCode = { | |
| ".-": "a", | |
| "-...": "b", | |
| "-.-.": "c", | |
| "-..": "d", | |
| ".": "e", | |
| "..-.": "f", | |
| "--.": "g", | |
| "....": "h", | |
| "..": "i", | |
| ".---": "j", | |
| "-.-": "k", | |
| ".-..": "l", | |
| "--": "m", | |
| "-.": "n", | |
| "---": "o", | |
| ".--.": "p", | |
| "--.-": "q", | |
| ".-.": "r", | |
| "...": "s", | |
| "-": "t", | |
| "..-": "u", | |
| "...-": "v", | |
| ".--": "w", | |
| "-..-": "x", | |
| "-.--": "y", | |
| "--..": "z", | |
| "-----": "0", | |
| ".----": "1", | |
| "..---": "2", | |
| "...--": "3", | |
| "....-": "4", | |
| ".....": "5", | |
| "-....": "6", | |
| "--...": "7", | |
| "---..": "8", | |
| "----.": "9", | |
| "": " " | |
| } | |
| function decode(str) { | |
| console.log(str.split(" ")) | |
| // implement morse decode here | |
| return str.split(" ").reduce((result, word) => { | |
| result += morseCode[word] | |
| return result | |
| }, "") | |
| } | |
| console.log(decode(".... . .-.. .-.. --- .-- --- .-. .-.. -..")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment