MCPcopy Create free account
hub / github.com/IQEngine/IQEngine / groupContiguousIndexes

Function groupContiguousIndexes

client/src/utils/group.ts:1–22  ·  view source on GitHub ↗
(indexes: number[])

Source from the content-addressed store, hash-verified

1export function groupContiguousIndexes(indexes: number[]) {
2 const contigousIndexes: { start: number; count: number }[] = [];
3 if (indexes.length === 0) {
4 return contigousIndexes;
5 }
6 indexes.sort((a, b) => a - b);
7 for (let i = 0; i < indexes.length; i++) {
8 const index = indexes[i];
9 if (i === 0) {
10 contigousIndexes.push({ start: index, count: 1 });
11 } else {
12 const lastContigousIndex = contigousIndexes[contigousIndexes.length - 1];
13 if (lastContigousIndex.start + lastContigousIndex.count === index) {
14 lastContigousIndex.count++;
15 } else {
16 contigousIndexes.push({ start: index, count: 1 });
17 }
18 }
19 }
20
21 return contigousIndexes;
22}

Callers 3

group.test.tsFile · 0.90
useGetIQDataFunction · 0.90
getIQDataBlocksMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected