-
-
Save ericls/227963789c00583c7b1403679571dd11 to your computer and use it in GitHub Desktop.
numpad decode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let keymap = [ | |
"", | |
"ABC", | |
"DEF", | |
"GHI", | |
"JKL", | |
"MNO", | |
"PQRS", | |
"TUV", | |
"WXYZ" | |
] | |
.map((item, i)=>{ | |
return { | |
[i+1]: item.split("").map( | |
(letter, i)=>{return {[i+1]: letter}} | |
).reduce((a, b)=>{ | |
return Object.assign({}, a, b) | |
}, {}) | |
} | |
}) | |
.reduce((a, b)=>{ | |
return Object.assign({}, a, b) | |
}, {}) | |
let input = process.argv.slice(2) | |
let result = input.map((code)=>{ | |
[i, j] = code.split("") | |
return keymap[i][j] | |
}).join("") | |
console.log(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment