Skip to content

Instantly share code, notes, and snippets.

@ericls

ericls/numpad.js Secret

Created September 1, 2016 18:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericls/227963789c00583c7b1403679571dd11 to your computer and use it in GitHub Desktop.
Save ericls/227963789c00583c7b1403679571dd11 to your computer and use it in GitHub Desktop.
numpad decode
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