Skip to content

Instantly share code, notes, and snippets.

@ivanji
Created May 30, 2019 19:41
Show Gist options
  • Select an option

  • Save ivanji/ad931bec137195013decfeedbfbcc430 to your computer and use it in GitHub Desktop.

Select an option

Save ivanji/ad931bec137195013decfeedbfbcc430 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/sigudum
<!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>
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