Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const payPad = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [null, 0, null]];
- function getIndexes(n) {
- let arrayIndex = Math.floor((n - 1) / 3);
- let numberIndex = n - 1 - 3 * arrayIndex;
- return [arrayIndex, numberIndex];
- }
- function getPossibilies([arrayIndex, numberIndex]) {
- const resullt = [];
- for (let i = 0; i <= 3; i++) {
- if (arrayIndex - i === 0) {
- for (let j = 0; j < 3; j++) {
- if (Math.abs(numberIndex - j) < 2) {
- resullt.push(payPad[i][j]);
- }
- }
- }
- if (Math.abs(i - arrayIndex) == 1) {
- resullt.push(payPad[i][numberIndex]);
- }
- }
- return resullt;
- }
- function getPins(observed) {
- const result = [];
- const possibilities = [];
- observed.split("").forEach(n => {
- possibilities.push(getPossibilies(getIndexes(Number(n))));
- });
- for (let i = 0; i < possibilities[0].length; i++) {
- let str = `${possibilities[0][i]}`;
- for (let j = 1; j < possibilities.length; j++) {
- for (let k = 0; k < possibilities[j].length; k++) {
- str += possibilities[j][k];
- if (str.length == observed.length) {
- result.push(str);
- str = `${possibilities[0][i]}`;
- }
- }
- }
- }
- return result;
- }
- getPins("11");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement