Last active
December 16, 2019 01:49
-
-
Save jmas/9c45da00918060a725558bb07eac53d3 to your computer and use it in GitHub Desktop.
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
var square = | |
` +-+ | |
| | |
+-+-+ | |
| | - | |
+-+-+`; | |
var points = []; | |
var jumpers = []; | |
var relations = []; | |
square.split('\n').forEach((line, lineIndex) => { | |
line.split('').forEach((char, charIndex) => { | |
if (char === '+') { | |
points.push([lineIndex, charIndex]); | |
} | |
if (char === '-' || char === '|') { | |
jumpers.push([lineIndex, charIndex]); | |
} | |
}); | |
}); | |
points.forEach(point => { | |
jumpers.forEach(jumper => { | |
if ( | |
(point[0] === jumper[0] && (point[1] === jumper[1]-1 || point[1] === jumper[1]+1)) || | |
(point[1] === jumper[1] && (point[0] === jumper[0]-1 || point[0] === jumper[0]+1)) | |
) { | |
if (relations.some(item => item[0] === point[0] && item[1] === point[1]) === false) { | |
relations.push(point); | |
} | |
} | |
}); | |
}); | |
// relations = (8 relations) | |
[[0,2],[0,4],[2,0],[2,2],[2,4],[4,0],[4,2],[4,4]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment