Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //use node.js to run this
- //steps through the message prompting for letter selection
- const prompts = require('prompts');
- const alphabet = {
- '.-': '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'
- }
- let message = '.-..--..-..-...--..-...-.--.-.-...-..--..-.--...-.-...-.-...--.-.-..--..-.-...-.-.-...-.-...--.-' //pompeo message - using q as last char
- //let message = '.--......-...--.--.-------...--.--.---.-.-...-..' //where we go one we go all
- let phrase = ''
- let letter = ''
- async function main(){
- const array = message.split('')
- for(let i=0,len=array.length;i<len;){
- const st = array[i]
- const nd = array[i] + array[i + 1]
- const rd = array[i] + array[i + 1] + array[i + 2]
- const th = array[i] + array[i + 1] + array[i + 2] + array[i + 3]
- //console.log({st, nd, rd, th})
- const stl = alphabet[st]
- const ndl = alphabet[nd]
- const rdl = alphabet[rd]
- const thl = alphabet[th]
- //console.log({stl, ndl, rdl, thl})
- const response = await prompts({
- type: 'number',
- name: 'value',
- message: `Pick a letter
- 1: ${stl},
- 2: ${ndl},
- 3: ${rdl},
- 4: ${thl},
- 5: space`,
- validate: value => value < 1 || value > 5? 'Must be 1 - 4' : true
- });
- switch(response.value){
- case 1: letter = stl
- break;
- case 2: letter = ndl
- break;
- case 3: letter = rdl
- break;
- case 4: letter = thl
- break
- case 5: letter = ' '
- }
- if(response.value !== 5){
- i = i + response.value
- }
- phrase += letter
- console.log({phrase, i})
- }
- }
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement