Skip to content

feat(micro-utilities): add compute-gcd to replacements - #1288

Merged
43081j merged 1 commit into
e18e:mainfrom
lyn1dev:feat/add-compute-gcd
Nov 25, 2026
Merged

43081j merged 1 commit into
e18e:mainfrom
lyn1dev:feat/add-compute-gcd

Conversation

@lyn1dev

@lyn1dev lyn1dev commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

🔗 Linked issue

resolves #1207

📚 Description

Adds the compute-gcd module to the micro-utilities manifest, mapped to a new snippet::gcd replacement. The replacement follows the shape of the recent compute-lcm entry: a small recursive helper that returns the greatest common divisor of two integers, with Math.abs on the base case so that negative inputs behave like the package (for example gcd(-12, 8) is 4).

The mapping and the snippet are inserted in the existing sort order of the manifest.

Testing

  • node scripts/sort-manifests.js leaves the manifest unchanged, so the new keys are in sorted position.
  • pnpm lint:manifests (node --experimental-vm-modules scripts/validate-modules.js) reports OK for the JSON-schema validation and the manifest problem checks.
  • Prettier reports no formatting issues for the changed manifest (tr -d '\r' < manifests/micro-utilities.json > .tmp-mu.json && npx prettier --check .tmp-mu.json; the checkout uses CRLF locally, which is why the repository-wide pnpm lint:format reports the same 188 pre-existing files on an unmodified checkout).
  • A small script that imports the built package (dist/main.js) asserts that all.mappings['compute-gcd'] is {type: 'module', moduleName: 'compute-gcd', replacements: ['snippet::gcd']}, that all.replacements['snippet::gcd'] exists, and evaluates the snippet example: gcd(48, 18) === 6, gcd(17, 5) === 1, gcd(0, 5) === 5, gcd(-12, 8) === 4, gcd(9, 0) === 9. The same script fails before the change because the mapping is undefined.

AI was used to write this code.

Map the compute-gcd package to a snippet::gcd replacement, mirroring the
compute-lcm entry. The snippet computes the greatest common divisor of two
integers recursively and keeps the sign handling of the package by taking the
absolute value of the base case.
@maksimgm

Copy link
Copy Markdown
Contributor

checked it against [email protected] and it matches for pairs of integers, including negatives and zero. the package also takes more than two values (gcd(12, 18, 24)), so maybe reduce over ...values like the lcm snippet in #1231

@43081j

43081j commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

i think we can keep it simple, to two values. the user can figure it out if they need more 👍

@43081j
43081j merged commit 2646d76 into e18e:main Nov 25, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Replacement]: compute-gcd

3 participants