Skip to content

Commit

Permalink
Highest match
Browse files Browse the repository at this point in the history
  • Loading branch information
JrMasterModelBuilder committed Dec 29, 2024
1 parent 4efc05e commit 0867918
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion util/ia.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,22 @@ export function groupFilesCaching() {
}

export function findGroup(prefix, packages) {
const matches = new Map();
let most = 0;
const pre = `${prefix}-`;
for (const p of packages) {
const parsed = parsePackageUrl(p.source);
if (parsed && parsed.item.startsWith(pre)) {
return parsed.item;
const total = (matches.get(parsed.item) || 0) + 1;
if (total > most) {
most = total;
}
matches.set(parsed.item, total);
}
}
for (const [item, total] of matches) {
if (total === most) {
return item;
}
}
return null;
Expand Down

0 comments on commit 0867918

Please sign in to comment.