Created
January 31, 2017 17:14
-
-
Save railsstudent/3c40de3a53569fe397631e93fafbac3f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function getPINs(observed) { | |
// return [observed].concat(getPINsHelper(observed)); | |
// return getPINsHelper(observed); | |
let adjacentPins = { | |
'1': ['1','2','4'], | |
'2': ['1','2','3','5'], | |
'3': ['2','3','6'], | |
'4': ['1','4','5','7'], | |
'5': ['2','4','5','6','8'], | |
'6': ['3','5','6','9'], | |
'7': ['4','7','8'], | |
'8': ['5','7','8','9','0'], | |
'9': ['6','8','9'], | |
'0': ['0', '8'] | |
}; | |
if (observed.length === 1) { | |
return adjacentPins[observed]; | |
} | |
let allPins = []; | |
let subPins = getPINs(observed.substring(1)); | |
adjacentPins[observed[0]].forEach((p) => { | |
allPins = allPins.concat(subPins.reduce((acc, sp) => { | |
acc.push(p + sp); | |
return acc; | |
}, [])); | |
}); | |
return allPins; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment