MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / compareVersionsDesc

Function compareVersionsDesc

telemetry-dashboard/src/api.ts:189–204  ·  view source on GitHub ↗

Newest first, numerically per segment, so 1.10.0 sorts above 1.9.0.

(a: string, b: string)

Source from the content-addressed store, hash-verified

187
188/** Newest first, numerically per segment, so 1.10.0 sorts above 1.9.0. */
189function compareVersionsDesc(a: string, b: string): number {
190 const pa = a.split(/[.-]/);
191 const pb = b.split(/[.-]/);
192 for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
193 const na = Number(pa[i]);
194 const nb = Number(pb[i]);
195 if (Number.isFinite(na) && Number.isFinite(nb)) {
196 if (na !== nb) return nb - na;
197 } else {
198 const sa = pa[i] ?? '';
199 const sb = pb[i] ?? '';
200 if (sa !== sb) return sb.localeCompare(sa);
201 }
202 }
203 return 0;
204}
205
206// ---------------------------------------------------------------------------
207// /api/meta

Callers 1

breakdownFunction · 0.85

Calls 1

NumberInterface · 0.85

Tested by

no test coverage detected