smsmslib 1.0.69 → 1.0.71

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -35,22 +35,25 @@ from "./arraynew.js";
35
35
  /**
36
36
  * Creates a multi-dimensional array (matrix) with specified dimensions.
37
37
  * This function constructs a nested array structure based on the provided
38
- * dimension arguments.
38
+ * dimension array.
39
39
  *
40
- * @param {...number} ai_dim [in]
41
- * A variable number of arguments defining the size of each dimension.
42
- * For example, `sj_mat_new(2, 3)` creates a 2x3 matrix. All arguments
40
+ * @param {number[]} ai_dim [in]
41
+ * An array of integers defining the size of each dimension.
42
+ * For example, `sj_mat_new([2, 3], 0)` creates a 2x3 matrix. All elements
43
43
  * must be positive integers.
44
44
  *
45
+ * @param {any} initial [in]
46
+ * The value to fill the deepest level of the newly created array with.
47
+ *
45
48
  * @returns {Array | null}
46
- * A new multi-dimensional array initialized with 0 at the deepest level.
49
+ * A new multi-dimensional array initialized with the `initial` value.
47
50
  * Returns `null` if any dimension is invalid or if allocation fails.
48
51
  *
49
52
  * @see mat_new_init
50
53
  * @see mat_new_push
51
54
  * @see mat_new_pop
52
55
  */
53
- export function sj_mat_new(...ai_dim)
56
+ export function sj_mat_new(ai_dim, initial)
54
57
  {
55
58
  let a_mat = null;
56
59
  const aa_stack = sj_array_new(0);
@@ -68,7 +71,7 @@ export function sj_mat_new(...ai_dim)
68
71
  }
69
72
  else
70
73
  {
71
- sj_array_lengthen(a_mat, ai_dim[aa_stack.length], 0);
74
+ sj_array_lengthen(a_mat, ai_dim[aa_stack.length], initial);
72
75
  a_mat = mat_new_pop(aa_stack, a_mat, ai_dim);
73
76
  }
74
77
  }
@@ -93,9 +96,10 @@ export function sj_mat_new(...ai_dim)
93
96
  */
94
97
  function mat_new_init(ai_dim)
95
98
  {
96
- let a_mat = null;
99
+ let a_mat = null;
100
+ const b_array = Array.isArray(ai_dim);
97
101
 
98
- if (0 < ai_dim.length)
102
+ if (b_array && (0 < ai_dim.length))
99
103
  {
100
104
  const b_every_ok =
101
105
  ai_dim.every(i_dim => Number.isInteger(i_dim) && (0 < i_dim));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "smsmslib",
3
- "version": "1.0.69",
3
+ "version": "1.0.71",
4
4
  "description": "Reusable functions for me.",
5
5
  "files": [
6
6
  "javascr/**/*.js",
@@ -19,6 +19,6 @@
19
19
  "author": "",
20
20
  "license": "ISC",
21
21
  "dependencies": {
22
- "smsmslib": "^1.0.69"
22
+ "smsmslib": "^1.0.71"
23
23
  }
24
24
  }