Repository navigation
feat(micro-utilities): add compute-gcd to replacements - #1288
Merged
Merged
Conversation
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.
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 ( |
Contributor
|
i think we can keep it simple, to two values. the user can figure it out if they need more 👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔗 Linked issue
resolves #1207
📚 Description
Adds the
compute-gcdmodule to themicro-utilitiesmanifest, mapped to a newsnippet::gcdreplacement. The replacement follows the shape of the recentcompute-lcmentry: a small recursive helper that returns the greatest common divisor of two integers, withMath.abson the base case so that negative inputs behave like the package (for examplegcd(-12, 8)is4).The mapping and the snippet are inserted in the existing sort order of the manifest.
Testing
node scripts/sort-manifests.jsleaves the manifest unchanged, so the new keys are in sorted position.pnpm lint:manifests(node --experimental-vm-modules scripts/validate-modules.js) reportsOKfor the JSON-schema validation and the manifest problem checks.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-widepnpm lint:formatreports the same 188 pre-existing files on an unmodified checkout).dist/main.js) asserts thatall.mappings['compute-gcd']is{type: 'module', moduleName: 'compute-gcd', replacements: ['snippet::gcd']}, thatall.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 isundefined.AI was used to write this code.