JSFiddle - React, Tailwind, and code Playground

by Lazaro Contreras

HTML

<p>Click the button to join the array elements into a string.</p>

<button onclick="decodeMorse('  aa    a aaaa sd    ')">Try it</button>

<p id="demo"></p>

<script>
function decodeMorse(morseCode){
  document.querySelector("p").innerHTML = morseCode.trim().split(/  | /).map( (code) => code || 'z').join(' ');
}
</script>