function generatePoints(minX, maxX) {
let letters = 'abcdefghijklmnopqrstuvwxyz';
let points = letters.split('').map((c) => {
return {id:c,
x: minX + Math.random()*(maxX-minX)}
});
points.sort((a,b) => a.x - b.x);
return points;
}
function findNeighbours(points, minDistance) {
let frame = [];
let neighbours = new Set();
for (point of points) {
while ((frame.length > 0) && ((point.x - frame[0].x) > minDistance)) {
frame.shift();
}
for (framePoint of frame) {
neighbours.add(framePoint.id + point.id);
}
frame.push(point);
}
return neighbours;
}
let points = generatePoints(0, 1000);
for (point of points) {
console.log(point);
}
for (pair of findNeighbours(points, 10)) {
console.log(pair);
}