utils/splitFullTrackIntoTrackSections.ts
unknown
plain_text
2 years ago
610 B
6
Indexable
export const splitFullTrackIntoTrackSections = (
tracks: any[],
stops: string[],
) => {
const sectionGroups = [];
let nextStopIdx = 1;
let currentSection: any[] = [];
tracks.forEach(point => {
const {station_1} = point;
if (station_1 !== stops[nextStopIdx]) {
currentSection.push(point);
} else {
const lastPoint = {...point, station_2: point.station_1};
sectionGroups.push([...currentSection, lastPoint]);
currentSection = [point];
nextStopIdx++;
}
});
sectionGroups.push(currentSection);
sectionGroups.splice(-1);
return sectionGroups;
};
Editor is loading...