Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Javascript -- v1.2.0: Reimplement esm transpilation, and swap to it as the default. #479

Merged
merged 149 commits into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
149 commits
Select commit Hold shift + click to select a range
e0ce087
Add links to the devlog
Skenvy Sep 26, 2022
acbb5e5
Add the default package json
Skenvy Oct 3, 2022
d5bb46c
Merge branch 'main' into javascript
Skenvy Oct 12, 2022
1874a07
Merge branch 'main' into javascript
Skenvy Oct 12, 2022
58bd634
Add more details to the package.json
Skenvy Oct 15, 2022
a6f7b90
A lot of comments in the devlog
Skenvy Oct 16, 2022
bc115c2
Update the workflows and add some basic recipes and remove the exit 1…
Skenvy Oct 30, 2022
96ebaed
Add cache dependency path to subdir
Skenvy Oct 30, 2022
9ab638e
Remove caching in setup-node
Skenvy Oct 30, 2022
b82f5a5
Add dist download and single publish recipe
Skenvy Oct 30, 2022
da8652d
Uncomment publish-npm
Skenvy Oct 30, 2022
ae6bad9
Remove the NA placeholder password in the java-test workflow, codeQL …
Skenvy Oct 30, 2022
41d9c76
Merge branch 'main' into javascript
Skenvy Oct 31, 2022
9b5ee75
Fix the missing permssions for the nested codeql step and add them to…
Skenvy Oct 31, 2022
5ab3c1d
Merge branch 'main' into javascript
Skenvy Oct 31, 2022
b36cc65
Remove the trailing slash on the path, and add a release upload target
Skenvy Oct 31, 2022
165d125
Add a word to the package
Skenvy Oct 31, 2022
2867401
Merge branch 'main' into javascript
Skenvy Oct 31, 2022
5255579
Whoops, remove the clean off publish
Skenvy Oct 31, 2022
d80db40
Bump the package.json to trigger package file changed
Skenvy Oct 31, 2022
e71f36c
Merge branch 'main' into javascript
Skenvy Oct 31, 2022
ff21c00
Add missing permission for publishing a package to github
Skenvy Oct 31, 2022
d046f7c
Merge branch 'main' into javascript
Skenvy Oct 31, 2022
3118378
Add npm-gh reference in main readme
Skenvy Oct 31, 2022
8d4938a
Add module dichotomy paragraph to devlog
Skenvy Nov 5, 2022
e9632eb
Merge branch 'main' into javascript
Skenvy Nov 6, 2022
8711eda
Merge branch 'main' into javascript
Skenvy Jan 15, 2023
b5a2d7a
Add mention of typescript
Jan 15, 2023
99ec339
Added some typescript settings to run tsc for cjs and mjs
Jan 16, 2023
da486a0
Added mocha-chai test setup for unit test framework.
Mar 27, 2023
aacb7d9
Bump emojis
Skenvy Mar 27, 2023
b9bd9f5
Some further comments regarding the snyk guide
Skenvy Mar 27, 2023
ae56b7a
Bump version
Mar 27, 2023
20ad21c
Run pack to have the library up to date.
Mar 27, 2023
474a0a4
Merge branch 'main' into javascript
Mar 27, 2023
932d538
Merge branch 'main' into javascript
Skenvy Apr 7, 2023
9f521d5
WIP fuse together snippets from the julia, java, and python implement…
Apr 8, 2023
64d01b9
Print the first layer of deps installed in ci
Apr 8, 2023
d86d59d
Change the minimum node version to 14.
Apr 8, 2023
48822a6
Update engine requires and install eslint
Apr 9, 2023
fb3dbe8
Add a linting step to CI (this push will fail on linting)
Apr 9, 2023
3dc78fd
Try adding AirBnB eslint config
Apr 9, 2023
24f9b9a
Fix test issue (lint will fail)
Apr 9, 2023
08340a1
Fewer linting errors
Apr 10, 2023
3b0eb60
Linter only warning now.
Apr 10, 2023
dd008ae
Format devlog
Apr 10, 2023
d508e6a
Add the reverse function
Apr 10, 2023
9d2793c
Tested and linted the reverse function
Apr 10, 2023
c2602fd
Add a recipe to fail if the checked in JS mismatches with the checked…
Apr 10, 2023
440b71b
Clean before the new verify
Apr 10, 2023
ebd3d00
Comment about docs gene
Apr 10, 2023
3674010
Install typedoc and tsdoc lint
Apr 10, 2023
ac99b63
Add tsdoc linter and try to make comments tsdoc-ish
Apr 10, 2023
70bb9ff
Recipe for docs
Apr 10, 2023
5eeae0a
Less cleaning when doccing
Apr 10, 2023
4516a92
Comment on attempt at JSDoc
Skenvy Apr 10, 2023
d685d32
Comment about setting up the docs target branch
Apr 10, 2023
f3e7d35
Bump up the version to test the whole CICD for javascript, with the f…
Apr 10, 2023
0288570
Retranspile the js files
Apr 10, 2023
2b87172
Add the devDependencies to the docs step
Skenvy Apr 10, 2023
515fec8
Stop windows from corrupting the line endings that eslint requires
Skenvy Apr 10, 2023
c971d61
Merge branch 'main' into javascript
Skenvy Apr 11, 2023
c078d06
Merge branch 'main' into javascript
Skenvy Apr 25, 2023
c7c279e
Add words to the readme
Apr 25, 2023
d1edc65
yike the lock
Apr 25, 2023
2944619
Up the node version in CI to one that bumps npm over 8.6
Apr 25, 2023
0ba765c
version
Apr 25, 2023
57aa219
Merge branch 'main' into javascript
Skenvy Apr 25, 2023
a49b99c
Merge branch 'main' into javascript
Jun 22, 2023
b3a8d9e
npm up
Jun 22, 2023
9085688
Add stoppingTimeTerminus
Jun 22, 2023
086bf17
transpile
Jun 22, 2023
5770593
wip adding hailstone
Jun 22, 2023
4fbecdf
transpile
Jun 22, 2023
35dc605
Add make for http-server and comment regarding __namedParameters
Jun 24, 2023
57c82b0
Swap from a named interface to anonymous interfaces i.e. object liter…
Jun 25, 2023
2bb5004
line length
Jun 25, 2023
b5cbbfb
WIP tests for hailstone sequence
Jun 25, 2023
2153c0f
WIP tests for hailstone sequence
Jun 25, 2023
70f380c
Finished testing hailstones
Jun 25, 2023
d0ee908
Bump to 0.4.0
Skenvy Jun 25, 2023
d9b6e33
Merge branch 'main' into javascript
Skenvy Jun 25, 2023
982d1c4
Stopping Time
Jun 26, 2023
21bb328
split into multiple files
Jun 26, 2023
9de2615
cutover to multiple files, tests and lints work
Jun 26, 2023
9e02a65
Add coverage reports being generated into docs
Jun 26, 2023
c14422f
coverage report handled
Jun 26, 2023
b5d22e8
pkg and lib
Jun 26, 2023
7576741
Merge branch 'main' into javascript
Skenvy Jun 27, 2023
e068ede
WIP tree graph
Jun 27, 2023
5a8a23e
assign the provided empty map in the test tgn's
Jun 27, 2023
89d7fcb
swap tgn to subtree
Skenvy Jun 27, 2023
93c102b
Set up the deep equals test for tree graph
Skenvy Jun 28, 2023
5a8904f
test, lint, and verify
Skenvy Jun 28, 2023
a63ba77
bump checkout
Skenvy Jun 28, 2023
b2c3de6
Add cache, add a basic stub for demos, and add comments regarding deno
Skenvy Jun 28, 2023
dfdb501
fix wf default and add node types to demo
Skenvy Jun 28, 2023
2d953d3
fix name of needed wf job
Skenvy Jun 28, 2023
ddf96f1
dot the demo folder
Skenvy Jun 28, 2023
8ef25e5
pkg
Jun 28, 2023
6275e19
Does setting up node with the development version fix npm not running…
Skenvy Jun 28, 2023
113113a
ok, ls the dir first, but also see if strip version manually works
Skenvy Jun 28, 2023
4a43ef9
but without another thing running first it doesn't run preinstall??
Skenvy Jun 29, 2023
f554f19
Does changing from preinstall to prepare let it know to run before th…
Skenvy Jun 29, 2023
10c6ea3
Does using the full name 'install' fix it?
Skenvy Jun 29, 2023
4ec9dd8
ok clearly lifecycle scripts are fucked
Skenvy Jun 29, 2023
8066106
Add ts demos
Jun 29, 2023
fe3ffbc
remove spaces
Jun 29, 2023
7f6dcc9
bump package to first major version
Jun 29, 2023
34fde4c
Merge branch 'main' into javascript
Skenvy Jun 29, 2023
002838f
Merge branch 'main' into javascript
Skenvy Jul 5, 2023
1f2a3f1
Stop testing node on version 17 and 19
Jul 5, 2023
cbd0b4a
Merge branch 'main' into javascript
Nov 2, 2023
022eb13
Set new minor release to update allowed engines
Nov 2, 2023
db578bc
Add wraps in the make to preempt nvm use on every npm command
Nov 2, 2023
b0c0425
Add overwrite of the nvmrc for the test steps
Nov 2, 2023
3d963bf
put install recipes in conditional make vars to not use nvm on windows
Nov 2, 2023
bf0d331
Merge branch 'main' into javascript
Skenvy Nov 2, 2023
8dd8255
Install nvm and npm versions before using make publish
Nov 2, 2023
ce7066b
Merge branch 'main' into javascript
Skenvy Mar 15, 2024
bfc5f87
Merge branch 'main' into javascript
Skenvy Mar 15, 2024
6fb3992
Merge branch 'main' into javascript
Skenvy Mar 15, 2024
19d82a9
Ran npm i on the unchanged package
Skenvy Mar 16, 2024
420f022
Bump mocha, @types/mocha, @types/node
Skenvy Mar 16, 2024
9c820c4
Bump everything except chai
Skenvy Mar 16, 2024
62b89d6
Bump chai to latest 4.x
Skenvy Mar 16, 2024
616dd0d
Merge branch 'main' into javascript
Skenvy Mar 16, 2024
248f85a
Bump chai to latest
Skenvy Mar 16, 2024
9dbd209
Add a node-options loader to use esm with mocha
Skenvy Mar 16, 2024
a91a610
wip trying different things to let chai v5
Skenvy Mar 16, 2024
00a11a8
Remove the attempt to make chai v5 work
Skenvy Mar 16, 2024
61297bf
very WIP, writing about this ridiculous ecosystem
Skenvy Mar 16, 2024
197dea7
demo to assert imports of the project work
Skenvy Mar 16, 2024
31b144e
Add back the previous copy of the transpiled result so there's less d…
Skenvy Mar 16, 2024
034408a
Remove the src and tests changes to record what the errors were
Skenvy Mar 16, 2024
e65684f
Revert all the things done to fix issues to replay the errors
Skenvy Mar 16, 2024
1dd284a
make build works
Skenvy Mar 16, 2024
e3f112f
added more specificity to the demo steps, wip mjs'ing and cjs'ing the…
Skenvy Mar 17, 2024
ce86c20
the project is buildable and the demo runs!
Skenvy Mar 17, 2024
007574f
use esm tsconf for docs
Skenvy Mar 17, 2024
65a93ef
fix ems -> esm and add use of mocha tsconf in covr
Skenvy Mar 17, 2024
7326064
Update setup-node action
Skenvy Mar 17, 2024
8cc3f60
update the version
Skenvy Mar 17, 2024
56a0ea7
fixed the ems -> esm typo in the demo package
Skenvy Mar 17, 2024
c377197
Change the demo test to use the new npm script names
Skenvy Mar 17, 2024
2f1294e
Add cross-env to let the test script continue to work on windows
Skenvy Mar 17, 2024
b1164e3
Add eol spec to gitattr to stop windows runners from not liking the n…
Skenvy Mar 17, 2024
277773d
Does changing package json to autocrlf fix the windows runner not lik…
Skenvy Mar 17, 2024
10f3f1a
Just don't bother with verifying the lib checkin on the matrix of run…
Skenvy Mar 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Swap from a named interface to anonymous interfaces i.e. object liter…
…al type parameters
  • Loading branch information
Skenvy committed Jun 25, 2023
commit 57c82b079db86b4c25895e3438ac36d310a39d55
6 changes: 4 additions & 2 deletions javascript/devlog.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,11 @@ We're now ready to add once again create an empty orphan branch;
1. `git commit -m "Initial empty orphan" --allow-empty`
1. `git push --set-upstream origin gh-pages-javascript`

### [__namedParameters](https://typedoc.org/tags/param/#destructured-parameters)
Apparently, specifying an input in the "destructured" format, like `({ n, P = 2n, a = 3n, b = 1n }: CollatzParameters)`, will lead to the name of the input being inferred by TypeDoc as `__namedParameters`. Any set of `@param` comments on a function that don't address this specific case will be ignored, but not necessarily in the order mentioned by the TypeDoc example.
### "Destructured Parameters" + "Object Literal", or interfaces?
Apparently, specifying an input in the ["destructured" format](https://typedoc.org/tags/param/#destructured-parameters) bound to an interface type, like `({ n, P = 2n, a = 3n, b = 1n }: CollatzParameters)` (where `CollatzParameters` is `{n:bigint, P?:bigint, a?:bigint, b?:bigint}`), will lead to the name of the input being inferred by TypeDoc as `__namedParameters`. Any set of `@param` comments on a function that don't address this specific case will be ignored, but not necessarily in the order mentioned by the TypeDoc example, or at least, not in the order I would assume, with the acknowledgement that I suffice the user acceptance testing role of "as a stupid user" per the KISS principle. So it's more probable the TypeDoc examples are fine, I'm just reading something extra that isn't there. So let's experiment a bit.

For example, in [this case](https://github.com/Skenvy/Collatz/blob/559c27e2595ea4ad980582ae2a037f79091f4913/javascript/src/index.ts#L124-L137) where there are four `@param`'s, the output TypeDoc yielded was [this](https://github.com/Skenvy/Collatz/blob/gh-pages/javascript/functions/Function.html#L27-L31), which simply lists `__namedParameters` as the name of the only input. Which is where I have now just seen and realised I got my `@param`'s wrong, for accurately displaying the inputs in TypeDoc's output. So now, how can this be fixed?

Well, testing this locally, there appear to be two ways to correctly yield a different name rather than `__namedParameters`. Either a single `@param`, for the one object input, _or_, a single `@param` that renames the top level object, along with the following lines obeying the [@param Object Literal](https://typedoc.org/tags/param/#object-literals) style, i.e. `* @param AnyNameHere - various options` followed by `* @param AnyNameHere.abc - property abc` will correctly yield renaming the `__namedParameters` to `AnyNameHere`, but I cannot get any way of rewriting the params underneath to yield their comments in the resulting site. Perhaps this is because it's not parsing the type of the object literal far enough to see the names of the parameters of the interface, and using the name of the interface instead of the "Object Literal" is a foot-gun? It would appear this is the case, because replacing the name of the interface with the "object literal" version of the interface, `{n:bigint, P?:bigint, a?:bigint, b?:bigint}`, allowed TypeDoc to yield the full documentation, as written on the function.

I'm not sure if there's a more preferred style one way or the other whether to use named interfaces or not, it would certainly uphold the notion of minimising the amount of repeated code, or at least repeated comments. But using a named interface rather than an "anonymous interface" ("object literal" as the type parameter) means the doc comments won't appear for each function. I think given these, I'd rather get rid of the named interface and swap over to object literals for each function's singular input's type parameter.
25 changes: 13 additions & 12 deletions javascript/lib/cjs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ function assertSaneParameterisation(P, a, b) {
exports.assertSaneParameterisation = assertSaneParameterisation;
/**
* Parameterised Collatz Function
* @param AnyNameHere - various options
* @param AnyNameHere.n - The value on which to perform the Collatz-esque function
* @param AnyNameHere.P - Modulus used to devide n, iff n is equivalent to (0 mod P). Default is 2.
* @param AnyNameHere.a - Factor by which to multiply n. Default is 3.
* @param AnyNameHere.b - Value to add to the scaled value of n. Default is 1.
* @param parameterisedInputs - Allows non-default (P,a,b)
* @param parameterisedInputs.n - The value on which to perform the Collatz-esque function
* @param parameterisedInputs.P - Modulus used to devide n, iff n is equivalent to (0 mod P). Default is 2.
* @param parameterisedInputs.a - Factor by which to multiply n. Default is 3.
* @param parameterisedInputs.b - Value to add to the scaled value of n. Default is 1.
* @returns the output of a single application of a Collatz-esque function.
* @throws FailedSaneParameterCheck
* Thrown if either P or a are 0.
Expand All @@ -114,10 +114,11 @@ function collatzFunction({ n, P = 2n, a = 3n, b = 1n }) {
exports.collatzFunction = collatzFunction;
/**
* Parameterised Collatz Inverse Function
* @param n - The value on which to perform the reverse Collatz function
* @param P - Modulus used to devide n, iff n is equivalent to (0 mod P). Default is 2.
* @param a - Factor by which to multiply n. Default is 3.
* @param b - Value to add to the scaled value of n. Default is 1.
* @param parameterisedInputs - Allows non-default (P,a,b)
* @param parameterisedInputs.n - The value on which to perform the reverse Collatz function
* @param parameterisedInputs.P - Modulus used to devide n, iff n is equivalent to (0 mod P). Default is 2.
* @param parameterisedInputs.a - Factor by which to multiply n. Default is 3.
* @param parameterisedInputs.b - Value to add to the scaled value of n. Default is 1.
* @returns the output of a single application of a Collatz-esque reverse function.
* @throws FailedSaneParameterCheck
* Thrown if either P or a are 0.
Expand Down Expand Up @@ -252,11 +253,11 @@ exports.HailstoneSequence = HailstoneSequence;
* of iterations to reach a value less than the initial value).
* @return (HailstoneSequence): A set of values that form the hailstone sequence.
*/
function hailstoneSequence({ n, P = 2n, a = 3n, b = 1n }, maxTotalStoppingTime, totalStoppingTime) {
function hailstoneSequence({ initialValue, P = 2n, a = 3n, b = 1n, maxTotalStoppingTime = 1000, totalStoppingTime = true }) {
// Call out the function before any magic returns to trap bad values.
const throwaway = collatzFunction({ n: n, P: P, a: a, b: b });
const throwaway = collatzFunction({ n: initialValue, P: P, a: a, b: b });
// Return the hailstone sequence.
return new HailstoneSequence(n, P, a, b, maxTotalStoppingTime, totalStoppingTime);
return new HailstoneSequence(initialValue, P, a, b, maxTotalStoppingTime, totalStoppingTime);
}
exports.hailstoneSequence = hailstoneSequence;
exports.default = {
Expand Down
61 changes: 24 additions & 37 deletions javascript/lib/cjs/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,39 +66,13 @@ export declare enum SequenceState {
* Thrown if either P or a are 0.
*/
export declare function assertSaneParameterisation(P: bigint, a: bigint, b: bigint): void;
/**
* Parameterised inputs
* @remarks
* Allow (P,a,b) to be optional, keyword inputs.
*/
export interface CollatzParameters {
/**
* The value on which to perform the operations; singular or iteratively.
*/
n: bigint;
/**
* The modulus. Modulus used to devide n, iff n is equivalent to (0 mod P).
* @defaultValue 2n
*/
P?: bigint;
/**
* The multiplicand. Factor by which to multiply n.
* @defaultValue 3n
*/
a?: bigint;
/**
* The addend. Value to add to the scaled value of n.
* @defaultValue 1n
*/
b?: bigint;
}
/**
* Parameterised Collatz Function
* @param AnyNameHere - various options
* @param AnyNameHere.n - The value on which to perform the Collatz-esque function
* @param AnyNameHere.P - Modulus used to devide n, iff n is equivalent to (0 mod P). Default is 2.
* @param AnyNameHere.a - Factor by which to multiply n. Default is 3.
* @param AnyNameHere.b - Value to add to the scaled value of n. Default is 1.
* @param parameterisedInputs - Allows non-default (P,a,b)
* @param parameterisedInputs.n - The value on which to perform the Collatz-esque function
* @param parameterisedInputs.P - Modulus used to devide n, iff n is equivalent to (0 mod P). Default is 2.
* @param parameterisedInputs.a - Factor by which to multiply n. Default is 3.
* @param parameterisedInputs.b - Value to add to the scaled value of n. Default is 1.
* @returns the output of a single application of a Collatz-esque function.
* @throws FailedSaneParameterCheck
* Thrown if either P or a are 0.
Expand All @@ -111,15 +85,21 @@ export declare function collatzFunction({ n, P, a, b }: {
}): bigint;
/**
* Parameterised Collatz Inverse Function
* @param n - The value on which to perform the reverse Collatz function
* @param P - Modulus used to devide n, iff n is equivalent to (0 mod P). Default is 2.
* @param a - Factor by which to multiply n. Default is 3.
* @param b - Value to add to the scaled value of n. Default is 1.
* @param parameterisedInputs - Allows non-default (P,a,b)
* @param parameterisedInputs.n - The value on which to perform the reverse Collatz function
* @param parameterisedInputs.P - Modulus used to devide n, iff n is equivalent to (0 mod P). Default is 2.
* @param parameterisedInputs.a - Factor by which to multiply n. Default is 3.
* @param parameterisedInputs.b - Value to add to the scaled value of n. Default is 1.
* @returns the output of a single application of a Collatz-esque reverse function.
* @throws FailedSaneParameterCheck
* Thrown if either P or a are 0.
*/
export declare function reverseFunction({ n, P, a, b }: CollatzParameters): bigint[];
export declare function reverseFunction({ n, P, a, b }: {
n: bigint;
P?: bigint;
a?: bigint;
b?: bigint;
}): bigint[];
/** Contains the results of computing a hailstone sequence. */
export declare class HailstoneSequence {
/** The set of values that comprise the hailstone sequence. */
Expand Down Expand Up @@ -168,7 +148,14 @@ export declare class HailstoneSequence {
* of iterations to reach a value less than the initial value).
* @return (HailstoneSequence): A set of values that form the hailstone sequence.
*/
export declare function hailstoneSequence({ n, P, a, b }: CollatzParameters, maxTotalStoppingTime: number, totalStoppingTime: boolean): HailstoneSequence;
export declare function hailstoneSequence({ initialValue, P, a, b, maxTotalStoppingTime, totalStoppingTime }: {
initialValue: bigint;
P?: bigint;
a?: bigint;
b?: bigint;
maxTotalStoppingTime?: number;
totalStoppingTime?: boolean;
}): HailstoneSequence;
declare const _default: {
collatzFunction: typeof collatzFunction;
reverseFunction: typeof reverseFunction;
Expand Down
2 changes: 1 addition & 1 deletion javascript/lib/cjs/types/index.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 13 additions & 12 deletions javascript/lib/esm/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ export function assertSaneParameterisation(P, a, b) {
}
/**
* Parameterised Collatz Function
* @param AnyNameHere - various options
* @param AnyNameHere.n - The value on which to perform the Collatz-esque function
* @param AnyNameHere.P - Modulus used to devide n, iff n is equivalent to (0 mod P). Default is 2.
* @param AnyNameHere.a - Factor by which to multiply n. Default is 3.
* @param AnyNameHere.b - Value to add to the scaled value of n. Default is 1.
* @param parameterisedInputs - Allows non-default (P,a,b)
* @param parameterisedInputs.n - The value on which to perform the Collatz-esque function
* @param parameterisedInputs.P - Modulus used to devide n, iff n is equivalent to (0 mod P). Default is 2.
* @param parameterisedInputs.a - Factor by which to multiply n. Default is 3.
* @param parameterisedInputs.b - Value to add to the scaled value of n. Default is 1.
* @returns the output of a single application of a Collatz-esque function.
* @throws FailedSaneParameterCheck
* Thrown if either P or a are 0.
Expand All @@ -108,10 +108,11 @@ export function collatzFunction({ n, P = 2n, a = 3n, b = 1n }) {
}
/**
* Parameterised Collatz Inverse Function
* @param n - The value on which to perform the reverse Collatz function
* @param P - Modulus used to devide n, iff n is equivalent to (0 mod P). Default is 2.
* @param a - Factor by which to multiply n. Default is 3.
* @param b - Value to add to the scaled value of n. Default is 1.
* @param parameterisedInputs - Allows non-default (P,a,b)
* @param parameterisedInputs.n - The value on which to perform the reverse Collatz function
* @param parameterisedInputs.P - Modulus used to devide n, iff n is equivalent to (0 mod P). Default is 2.
* @param parameterisedInputs.a - Factor by which to multiply n. Default is 3.
* @param parameterisedInputs.b - Value to add to the scaled value of n. Default is 1.
* @returns the output of a single application of a Collatz-esque reverse function.
* @throws FailedSaneParameterCheck
* Thrown if either P or a are 0.
Expand Down Expand Up @@ -258,11 +259,11 @@ export class HailstoneSequence {
* of iterations to reach a value less than the initial value).
* @return (HailstoneSequence): A set of values that form the hailstone sequence.
*/
export function hailstoneSequence({ n, P = 2n, a = 3n, b = 1n }, maxTotalStoppingTime, totalStoppingTime) {
export function hailstoneSequence({ initialValue, P = 2n, a = 3n, b = 1n, maxTotalStoppingTime = 1000, totalStoppingTime = true }) {
// Call out the function before any magic returns to trap bad values.
const throwaway = collatzFunction({ n: n, P: P, a: a, b: b });
const throwaway = collatzFunction({ n: initialValue, P: P, a: a, b: b });
// Return the hailstone sequence.
return new HailstoneSequence(n, P, a, b, maxTotalStoppingTime, totalStoppingTime);
return new HailstoneSequence(initialValue, P, a, b, maxTotalStoppingTime, totalStoppingTime);
}
export default {
collatzFunction,
Expand Down
Loading