Skip to content

Commit 99218f9

Browse files
committed
refactor: drop support for number as a dimensions argument
BREAKING CHANGE: passing a number as `dimensions` is no longer supported
1 parent ad33746 commit 99218f9

File tree

6 files changed

+53
-4396
lines changed

6 files changed

+53
-4396
lines changed

README.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,9 @@ import makeMatrix from "make-matrix";
3131

3232
### Create a matrix
3333

34-
To simply create an array of `n` dimensions, just pass `n` as the function's first parameter. And to create an array with exact dimensions, pass in an array of numbers.
34+
To create a matrix, pass in an array with the desired dimensions.
3535

3636
```js
37-
// create a 2D array
38-
const twoDimensionalArray = makeMatrix(2);
39-
4037
// create an array of size 3x3x2
4138
const threeByThreeByTwoArray = makeMatrix([3, 3, 2]);
4239
```
@@ -47,10 +44,10 @@ By default each point in the matrix will be initialised to `null` (so that if re
4744

4845
```js
4946
// create a 3x5 array, with each point equal to 0
50-
const twoDimensionalNumberArray = makeMatrix([3, 5], 0);
47+
const twoDNumberArray = makeMatrix([3, 5], 0);
5148

5249
// create a 2x6x5 array, with each point equal to "value"
53-
const threeDimensionalStringArray = makeMatrix([2, 6, 5], "value");
50+
const threeDStringArray = makeMatrix([2, 6, 5], "value");
5451
```
5552

5653
### Pass a callback for dynamic initial values
@@ -119,7 +116,7 @@ The `makeMatrix` algorithm is recursive and takes exponential time, or $O(2^n)$,
119116

120117
```ts
121118
makeMatrix<D, T>(
122-
dimensions: D | VectorOfLength<D>,
119+
dimensions: VectorOfLength<D>,
123120
initialValues?: T | ((vector: VectorOfLength<D>) => T) = null
124121
): Matrix<D, T>;
125122
```
@@ -128,7 +125,7 @@ makeMatrix<D, T>(
128125

129126
| Name | Description |
130127
| ------------- | ------------- |
131-
| `dimensions` | The desired dimensions of the matrix. A number or array of numbers. |
128+
| `dimensions` | The desired dimensions of the matrix. An array of numbers. |
132129
| `initialValues` | The value that each point in the matrix will initialise to. Can take any value. If a callback is passed, it will be run for each point in the matrix, which will be initialised to the callbacks returned value. (Optional — defaults to `null`). |
133130

134131
### Returns

benchmark/run-benchmark.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import * as fs from "fs";
33
import { context, getOctokit } from "@actions/github";
44
import benny from "benny";
5-
import makeMatrix from "../src/index.js";
5+
import { makeMatrix } from "../src/index.js";
66
import packageJson from "../package.json" assert { type: "json" };
77

88
const { name: packageName, version } = packageJson;
@@ -25,13 +25,10 @@ type Diff = {
2525
benny
2626
.suite(
2727
"make-matrix",
28-
benny.add("nDimensions", () => {
29-
makeMatrix(6);
30-
}),
31-
benny.add("specificDimensions", () => {
28+
benny.add("base", () => {
3229
makeMatrix([2, 4, 2, 4, 2]);
3330
}),
34-
benny.add("specific & callback", () => {
31+
benny.add("with callback", () => {
3532
makeMatrix([2, 4, 2, 4, 2], vector => `my position is ${vector.join()}`);
3633
}),
3734
benny.cycle(),

0 commit comments

Comments
 (0)