Skip to content

Instantly share code, notes, and snippets.

@jmas
Last active December 16, 2019 01:49
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 jmas/9c45da00918060a725558bb07eac53d3 to your computer and use it in GitHub Desktop.
Save jmas/9c45da00918060a725558bb07eac53d3 to your computer and use it in GitHub Desktop.
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