Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

decode morse code js

function decodeMorse(morseCode) {
  var ref = { 
    '.-':     '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',
    '.----':  '1',
    '..---':  '2',
    '...--':  '3',
    '....-':  '4',
    '.....':  '5',
    '-....':  '6',
    '--...':  '7',
    '---..':  '8',
    '----.':  '9',
    '-----':  '0',
  };

  return morseCode
    .split('   ')
    .map(
      a => a
        .split(' ')
        .map(
          b => ref[b]
        ).join('')
    ).join(' ');
}

var decoded = decodeMorse(".-- --- .-. -..   .-- --- .-. -..");
console.log(decoded);
Comment

PREVIOUS NEXT
Code Example
Javascript :: generate random date 
Javascript :: convert node.js to ES6 
Javascript :: python range in javascript 
Javascript :: ajax multipart/form-data 
Javascript :: angular add a new line from component 
Javascript :: jquery get body 
Javascript :: javascript use variable regex 
Javascript :: jquery today date 
Javascript :: string contains substring javascript 
Javascript :: regex pattern for strong password 
Javascript :: mac node change version 16 
Javascript :: closest javascript 
Javascript :: js get seconds difference 
Javascript :: post data from api using jquery ajax 
Javascript :: how to remove middle characters in string javascript 
Javascript :: react conditional styling 
Javascript :: onclick inline function react 
Javascript :: get value of key in object mongodb 
Javascript :: what is the type of children prop 
Javascript :: js convert to fraction 
Javascript :: how to make a button execute a javascript function 
Javascript :: run jest on single file 
Javascript :: js remove the last character from a string 
Javascript :: chrome extension get current tab from popup 
Javascript :: install bcrypt 
Javascript :: count number of word in javascript 
Javascript :: opencv rtsp stream python 
Javascript :: styled components import google font 
Javascript :: js window location relative path 
Javascript :: laravel return validation errors ajax 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =