QOL: Move source code under the src directory. (#1318)

This commit is contained in:
Angelos Bouklis
2023-10-15 15:52:48 +03:00
committed by GitHub
parent 30c8dcf730
commit 7625a3aa52
159 changed files with 102 additions and 71 deletions

View File

@ -0,0 +1,34 @@
// Segments are an array [ [start, end], … ]
import { Segment } from './types';
export const sortSegments = (segments: Segment[]) => {
segments.sort((segment1, segment2) =>
segment1[0] === segment2[0]
? segment1[1] - segment2[1]
: segment1[0] - segment2[0],
);
const compiledSegments: Segment[] = [];
let currentSegment: Segment | undefined;
for (const segment of segments) {
if (!currentSegment) {
currentSegment = segment;
continue;
}
if (currentSegment[1] < segment[0]) {
compiledSegments.push(currentSegment);
currentSegment = segment;
continue;
}
currentSegment[1] = Math.max(currentSegment[1], segment[1]);
}
if (currentSegment) {
compiledSegments.push(currentSegment);
}
return compiledSegments;
};