Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ Write your solution in `src/index.js`
## Prepare and test

- Install [Node.js](https://nodejs.org/en/)
- Clone this repository: `https://github.com/romacher/morse-decoder.git`
- Fork this repository: `https://github.com/romacher/morse-decoder.git`
- Clone your newly created repo: `https://github.com/<%your_github_username%>/morse-decoder/`
- Go to the folder `morse-decoder`
- Run `npm install` in command line
- Run `npm test` in command line
Expand Down
16 changes: 14 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,22 @@ const MORSE_TABLE = {
'-----': '0',
};

const decodeLetter = letter => {
let letter_code = letter.match(/.{1,2}/g).map(v => {
if (v === '10') return '.'
if (v === '11') return '-'
}).join('')
return MORSE_TABLE[letter_code]
}

const decodeWord = word => {
return word.match(/.{1,10}/g).map(decodeLetter).join('')
}

function decode(expr) {
// write your solution here
return expr.split('**********').map(decodeWord).join(' ')
}

module.exports = {
decode
}
}