import { wrapIndex } from './wrapIndex'; // The positions around `index` whose large photos the lightbox loads ahead, // nearest first and alternating next/previous (next, previous, next+1, …). // The list wraps around, so in a short list each photo appears once and the // current one never. export function neighbourIndexes( index: number, count: number, radius: number = 2, ): number[] { const result: number[] = []; for (let distance = 1; distance <= radius; distance++) { for (const candidate of [ wrapIndex(index + distance, count), wrapIndex(index - distance, count), ]) { if (candidate !== index && !result.includes(candidate)) { result.push(candidate); } } } return result; }