@gridsheet/functions 3.0.1 → 3.0.3

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.
@@ -1,10 +1,10 @@
1
- import { BaseFunction as y, conditionArg as b, ensureString as M, eachMatrix as m, stripMatrix as T, check as R, FormulaError as d, Sheet as w, createBooleanMask as q, ensureNumber as f } from "@gridsheet/core";
2
- const k = "Returns the average of a series of cells that meet a condition.";
3
- class S extends y {
1
+ import { BaseFunction as x, conditionArg as T, ensureString as E, eachMatrix as m, stripMatrix as R, isNumeric as A, check as N, ensureNumber as f, FormulaError as d, Sheet as b, createBooleanMask as k } from "@gridsheet/core";
2
+ const v = "Returns the average of a series of cells that meet a condition.";
3
+ class S extends x {
4
4
  constructor() {
5
- super(...arguments), this.example = 'AVERAGEIF(A1:A10,">20")', this.description = k, this.defs = [
5
+ super(...arguments), this.example = 'AVERAGEIF(A1:A10,">20")', this.description = v, this.defs = [
6
6
  { name: "range", description: "A condition range.", takesMatrix: !0, acceptedTypes: ["matrix"] },
7
- b,
7
+ T,
8
8
  {
9
9
  name: "average_range",
10
10
  description: "A range to be averaged.",
@@ -14,37 +14,37 @@ class S extends y {
14
14
  }
15
15
  ], this.category = "statistics";
16
16
  }
17
- main(t, n, r) {
18
- const e = M(n), a = [], i = [];
17
+ main(t, n, a) {
18
+ const e = E(n), r = [], i = [];
19
19
  m(
20
20
  t,
21
21
  (s) => {
22
- a.push(s);
22
+ r.push(s);
23
23
  },
24
24
  this.at
25
- ), r && m(
26
- r,
25
+ ), a && m(
26
+ a,
27
27
  (s) => {
28
28
  i.push(s);
29
29
  },
30
30
  this.at
31
31
  );
32
32
  let c = 0, o = 0;
33
- if (a.forEach((s, l) => {
34
- const h = T((r ? i[l] : s) ?? 0, this.at);
35
- typeof h == "number" && R(s, e) && (c += h, o++);
33
+ if (r.forEach((s, l) => {
34
+ const h = R((a ? i[l] : s) ?? 0, this.at);
35
+ A(h) && N(s, e) && (c += f(h), o++);
36
36
  }), o === 0)
37
37
  throw new d("#DIV/0!", "No cells match the condition.");
38
38
  return c / o;
39
39
  }
40
40
  }
41
41
  const I = "Returns the average of a range depending on multiple criteria.";
42
- class V extends y {
42
+ class V extends x {
43
43
  constructor() {
44
44
  super(...arguments), this.example = 'AVERAGEIFS(A1:A10, B1:B10, ">20")', this.description = I, this.defs = [
45
45
  { name: "average_range", description: "The range to be averaged.", takesMatrix: !0, acceptedTypes: ["matrix"] },
46
46
  { name: "range1", description: "First condition range.", takesMatrix: !0, acceptedTypes: ["matrix"] },
47
- { ...b, name: "condition1" },
47
+ { ...T, name: "condition1" },
48
48
  {
49
49
  name: "range2",
50
50
  description: "Additional condition range.",
@@ -53,42 +53,42 @@ class V extends y {
53
53
  optional: !0,
54
54
  variadic: !0
55
55
  },
56
- { ...b, name: "condition2", optional: !0, variadic: !0 }
56
+ { ...T, name: "condition2", optional: !0, variadic: !0 }
57
57
  ], this.category = "statistics";
58
58
  }
59
59
  validate(t) {
60
60
  const n = super.validate(t);
61
61
  if ((n.length - 1) % 2 !== 0)
62
62
  throw new d("#N/A", "AVERAGEIFS requires average_range and at least one range/condition pair.");
63
- if (!(n[0] instanceof w))
63
+ if (!(n[0] instanceof b))
64
64
  throw new d("#VALUE!", "First argument of AVERAGEIFS must be a range.");
65
- const r = n[0].numRows, e = n[0].numCols, a = [], i = [];
65
+ const a = n[0].numRows, e = n[0].numCols, r = [], i = [];
66
66
  for (let s = 1; s < n.length; s += 2) {
67
- if (!(n[s] instanceof w))
67
+ if (!(n[s] instanceof b))
68
68
  throw new d("#VALUE!", `Argument ${s + 1} of AVERAGEIFS must be a range.`);
69
- if (n[s].numRows !== r || n[s].numCols !== e)
69
+ if (n[s].numRows !== a || n[s].numCols !== e)
70
70
  throw new d("#VALUE!", "Array arguments to AVERAGEIFS are of different size.");
71
- a.push(n[s]), i.push(M(n[s + 1]));
71
+ r.push(n[s]), i.push(E(n[s + 1]));
72
72
  }
73
- const c = n[0], o = q(a, i, this.at);
73
+ const c = n[0], o = k(r, i, this.at);
74
74
  return [c, o];
75
75
  }
76
76
  main(t, n) {
77
- let r = 0, e = 0;
77
+ let a = 0, e = 0;
78
78
  return m(
79
79
  t,
80
- (a, i) => {
80
+ (r, i) => {
81
81
  if (i && n[i.y][i.x]) {
82
- const c = T(a ?? 0, this.at);
83
- typeof c == "number" && (r += c, e++);
82
+ const c = R(r ?? 0, this.at);
83
+ A(c) && (a += f(c), e++);
84
84
  }
85
85
  },
86
86
  this.at
87
- ), e === 0 ? new d("#DIV/0!", "No matching cells found for AVERAGEIFS.") : r / e;
87
+ ), e === 0 ? new d("#DIV/0!", "No matching cells found for AVERAGEIFS.") : a / e;
88
88
  }
89
89
  }
90
90
  const F = "Returns the median value in a numeric dataset.";
91
- class C extends y {
91
+ class C extends x {
92
92
  constructor() {
93
93
  super(...arguments), this.example = "MEDIAN(A1:A100)", this.description = F, this.defs = [
94
94
  {
@@ -102,11 +102,11 @@ class C extends y {
102
102
  }
103
103
  validate(t) {
104
104
  const n = [];
105
- for (const r of t)
105
+ for (const a of t)
106
106
  m(
107
- r,
107
+ a,
108
108
  (e) => {
109
- e == null || e === "" || typeof e == "boolean" || (typeof e == "number" || typeof e == "string" && !isNaN(Number(e))) && n.push(f(e));
109
+ e == null || e === "" || typeof e == "boolean" || A(e) && n.push(f(e));
110
110
  },
111
111
  this.at
112
112
  );
@@ -115,13 +115,13 @@ class C extends y {
115
115
  return [n];
116
116
  }
117
117
  main(t) {
118
- t.sort((r, e) => r - e);
118
+ t.sort((a, e) => a - e);
119
119
  const n = Math.floor(t.length / 2);
120
120
  return t.length % 2 === 0 ? (t[n - 1] + t[n]) / 2 : t[n];
121
121
  }
122
122
  }
123
123
  const D = "Returns the standard deviation based on a sample.";
124
- class B extends y {
124
+ class B extends x {
125
125
  constructor() {
126
126
  super(...arguments), this.example = "STDEV.S(A1:A100)", this.description = D, this.defs = [
127
127
  {
@@ -135,11 +135,11 @@ class B extends y {
135
135
  }
136
136
  validate(t) {
137
137
  const n = [];
138
- for (const r of t)
138
+ for (const a of t)
139
139
  m(
140
- r,
140
+ a,
141
141
  (e) => {
142
- e == null || e === "" || typeof e == "boolean" || (typeof e == "number" || typeof e == "string" && !isNaN(Number(e))) && n.push(f(e));
142
+ e == null || e === "" || typeof e == "boolean" || A(e) && n.push(f(e));
143
143
  },
144
144
  this.at
145
145
  );
@@ -148,12 +148,12 @@ class B extends y {
148
148
  return [n];
149
149
  }
150
150
  main(t) {
151
- const n = t.reduce((e, a) => e + a, 0) / t.length, r = t.reduce((e, a) => e + (a - n) ** 2, 0) / (t.length - 1);
152
- return Math.sqrt(r);
151
+ const n = t.reduce((e, r) => e + r, 0) / t.length, a = t.reduce((e, r) => e + (r - n) ** 2, 0) / (t.length - 1);
152
+ return Math.sqrt(a);
153
153
  }
154
154
  }
155
155
  const P = "Returns the standard deviation based on the entire population.";
156
- class $ extends y {
156
+ class $ extends x {
157
157
  constructor() {
158
158
  super(...arguments), this.example = "STDEV.P(A1:A100)", this.description = P, this.defs = [
159
159
  {
@@ -167,11 +167,11 @@ class $ extends y {
167
167
  }
168
168
  validate(t) {
169
169
  const n = [];
170
- for (const r of t)
170
+ for (const a of t)
171
171
  m(
172
- r,
172
+ a,
173
173
  (e) => {
174
- e == null || e === "" || typeof e == "boolean" || (typeof e == "number" || typeof e == "string" && !isNaN(Number(e))) && n.push(f(e));
174
+ e == null || e === "" || typeof e == "boolean" || A(e) && n.push(f(e));
175
175
  },
176
176
  this.at
177
177
  );
@@ -180,12 +180,12 @@ class $ extends y {
180
180
  return [n];
181
181
  }
182
182
  main(t) {
183
- const n = t.reduce((e, a) => e + a, 0) / t.length, r = t.reduce((e, a) => e + (a - n) ** 2, 0) / t.length;
184
- return Math.sqrt(r);
183
+ const n = t.reduce((e, r) => e + r, 0) / t.length, a = t.reduce((e, r) => e + (r - n) ** 2, 0) / t.length;
184
+ return Math.sqrt(a);
185
185
  }
186
186
  }
187
187
  const U = "Returns the variance based on a sample.";
188
- class _ extends y {
188
+ class _ extends x {
189
189
  constructor() {
190
190
  super(...arguments), this.example = "VAR.S(A1:A100)", this.description = U, this.defs = [
191
191
  {
@@ -199,11 +199,11 @@ class _ extends y {
199
199
  }
200
200
  validate(t) {
201
201
  const n = [];
202
- for (const r of t)
202
+ for (const a of t)
203
203
  m(
204
- r,
204
+ a,
205
205
  (e) => {
206
- e == null || e === "" || typeof e == "boolean" || (typeof e == "number" || typeof e == "string" && !isNaN(Number(e))) && n.push(f(e));
206
+ e == null || e === "" || typeof e == "boolean" || A(e) && n.push(f(e));
207
207
  },
208
208
  this.at
209
209
  );
@@ -212,12 +212,12 @@ class _ extends y {
212
212
  return [n];
213
213
  }
214
214
  main(t) {
215
- const n = t.reduce((r, e) => r + e, 0) / t.length;
216
- return t.reduce((r, e) => r + (e - n) ** 2, 0) / (t.length - 1);
215
+ const n = t.reduce((a, e) => a + e, 0) / t.length;
216
+ return t.reduce((a, e) => a + (e - n) ** 2, 0) / (t.length - 1);
217
217
  }
218
218
  }
219
219
  const L = "Returns the variance based on the entire population.";
220
- class Q extends y {
220
+ class Q extends x {
221
221
  constructor() {
222
222
  super(...arguments), this.example = "VAR.P(A1:A100)", this.description = L, this.defs = [
223
223
  {
@@ -231,11 +231,11 @@ class Q extends y {
231
231
  }
232
232
  validate(t) {
233
233
  const n = [];
234
- for (const r of t)
234
+ for (const a of t)
235
235
  m(
236
- r,
236
+ a,
237
237
  (e) => {
238
- e == null || e === "" || typeof e == "boolean" || (typeof e == "number" || typeof e == "string" && !isNaN(Number(e))) && n.push(f(e));
238
+ e == null || e === "" || typeof e == "boolean" || A(e) && n.push(f(e));
239
239
  },
240
240
  this.at
241
241
  );
@@ -244,12 +244,12 @@ class Q extends y {
244
244
  return [n];
245
245
  }
246
246
  main(t) {
247
- const n = t.reduce((r, e) => r + e, 0) / t.length;
248
- return t.reduce((r, e) => r + (e - n) ** 2, 0) / t.length;
247
+ const n = t.reduce((a, e) => a + e, 0) / t.length;
248
+ return t.reduce((a, e) => a + (e - n) ** 2, 0) / t.length;
249
249
  }
250
250
  }
251
251
  const G = "Returns the k-th percentile of values in a range, where k is in the range 0 to 1, inclusive.";
252
- class O extends y {
252
+ class O extends x {
253
253
  constructor() {
254
254
  super(...arguments), this.example = "PERCENTILE.INC(A1:A100, 0.9)", this.description = G, this.defs = [
255
255
  {
@@ -265,27 +265,27 @@ class O extends y {
265
265
  const n = f(t[1]);
266
266
  if (n < 0 || n > 1)
267
267
  throw new d("#NUM!", "Percentile must be between 0 and 1.");
268
- const r = [];
268
+ const a = [];
269
269
  if (m(
270
270
  t[0],
271
271
  (e) => {
272
- e == null || e === "" || typeof e == "boolean" || (typeof e == "number" || typeof e == "string" && !isNaN(Number(e))) && r.push(f(e));
272
+ e == null || e === "" || typeof e == "boolean" || A(e) && a.push(f(e));
273
273
  },
274
274
  this.at
275
- ), r.length === 0)
275
+ ), a.length === 0)
276
276
  throw new d("#NUM!", "PERCENTILE.INC requires at least one numeric value.");
277
- return [r, n];
277
+ return [a, n];
278
278
  }
279
279
  main(t, n) {
280
280
  t.sort((i, c) => i - c);
281
- const r = n * (t.length - 1), e = Math.floor(r), a = Math.ceil(r);
282
- return t[e] + (t[a] - t[e]) * (r - e);
281
+ const a = n * (t.length - 1), e = Math.floor(a), r = Math.ceil(a);
282
+ return t[e] + (t[r] - t[e]) * (a - e);
283
283
  }
284
284
  }
285
- const v = "Returns the quartile of a dataset, based on percentile values from 0 to 1, inclusive.";
286
- class X extends y {
285
+ const X = "Returns the quartile of a dataset, based on percentile values from 0 to 1, inclusive.";
286
+ class Y extends x {
287
287
  constructor() {
288
- super(...arguments), this.example = "QUARTILE.INC(A1:A100, 1)", this.description = v, this.defs = [
288
+ super(...arguments), this.example = "QUARTILE.INC(A1:A100, 1)", this.description = X, this.defs = [
289
289
  {
290
290
  name: "data",
291
291
  description: "The array or range of data to consider.",
@@ -303,27 +303,27 @@ class X extends y {
303
303
  const n = Math.floor(f(t[1]));
304
304
  if (n < 0 || n > 4)
305
305
  throw new d("#NUM!", "Quartile number must be between 0 and 4.");
306
- const r = [];
306
+ const a = [];
307
307
  if (m(
308
308
  t[0],
309
309
  (e) => {
310
- e == null || e === "" || typeof e == "boolean" || (typeof e == "number" || typeof e == "string" && !isNaN(Number(e))) && r.push(f(e));
310
+ e == null || e === "" || typeof e == "boolean" || A(e) && a.push(f(e));
311
311
  },
312
312
  this.at
313
- ), r.length === 0)
313
+ ), a.length === 0)
314
314
  throw new d("#NUM!", "QUARTILE.INC requires at least one numeric value.");
315
- return [r, n];
315
+ return [a, n];
316
316
  }
317
317
  main(t, n) {
318
318
  t.sort((c, o) => c - o);
319
- const e = n / 4 * (t.length - 1), a = Math.floor(e), i = Math.ceil(e);
320
- return t[a] + (t[i] - t[a]) * (e - a);
319
+ const e = n / 4 * (t.length - 1), r = Math.floor(e), i = Math.ceil(e);
320
+ return t[r] + (t[i] - t[r]) * (e - r);
321
321
  }
322
322
  }
323
- const Y = "Returns the rank of a number in a list of numbers. If more than one value has the same rank, the top rank of that set of values is returned.";
324
- class K extends y {
323
+ const K = "Returns the rank of a number in a list of numbers. If more than one value has the same rank, the top rank of that set of values is returned.";
324
+ class W extends x {
325
325
  constructor() {
326
- super(...arguments), this.example = "RANK.EQ(A1, A1:A100)", this.description = Y, this.defs = [
326
+ super(...arguments), this.example = "RANK.EQ(A1, A1:A100)", this.description = K, this.defs = [
327
327
  { name: "value", description: "The value whose rank will be determined.", acceptedTypes: ["number"] },
328
328
  {
329
329
  name: "data",
@@ -340,28 +340,28 @@ class K extends y {
340
340
  ], this.category = "statistics";
341
341
  }
342
342
  validate(t) {
343
- const n = f(t[0]), r = [];
343
+ const n = f(t[0]), a = [];
344
344
  if (m(
345
345
  t[1],
346
- (a) => {
347
- a == null || a === "" || typeof a == "boolean" || (typeof a == "number" || typeof a == "string" && !isNaN(Number(a))) && r.push(f(a));
346
+ (r) => {
347
+ r == null || r === "" || typeof r == "boolean" || A(r) && a.push(f(r));
348
348
  },
349
349
  this.at
350
- ), r.length === 0)
350
+ ), a.length === 0)
351
351
  throw new d("#NUM!", "RANK.EQ requires at least one numeric value in data.");
352
- if (!r.includes(n))
352
+ if (!a.includes(n))
353
353
  throw new d("#N/A", "Value not found in data range.");
354
354
  const e = t[2] ?? !1;
355
- return [n, r, e];
355
+ return [n, a, e];
356
356
  }
357
- main(t, n, r) {
358
- return n.sort((e, a) => r ? e - a : a - e), n.indexOf(t) + 1;
357
+ main(t, n, a) {
358
+ return n.sort((e, r) => a ? e - r : r - e), n.indexOf(t) + 1;
359
359
  }
360
360
  }
361
- const W = "Returns the correlation coefficient of two datasets.";
362
- class j extends y {
361
+ const j = "Returns the correlation coefficient of two datasets.";
362
+ class H extends x {
363
363
  constructor() {
364
- super(...arguments), this.example = "CORREL(A1:A100, B1:B100)", this.description = W, this.defs = [
364
+ super(...arguments), this.example = "CORREL(A1:A100, B1:B100)", this.description = j, this.defs = [
365
365
  {
366
366
  name: "data_y",
367
367
  description: "The range representing the dependent data.",
@@ -377,28 +377,28 @@ class j extends y {
377
377
  ], this.category = "statistics";
378
378
  }
379
379
  validate(t) {
380
- const n = [], r = [];
380
+ const n = [], a = [];
381
381
  if (m(
382
382
  t[0],
383
383
  (e) => {
384
- e == null || e === "" || typeof e == "boolean" || (typeof e == "number" || typeof e == "string" && !isNaN(Number(e))) && n.push(f(e));
384
+ e == null || e === "" || typeof e == "boolean" || A(e) && n.push(f(e));
385
385
  },
386
386
  this.at
387
387
  ), m(
388
388
  t[1],
389
389
  (e) => {
390
- e == null || e === "" || typeof e == "boolean" || (typeof e == "number" || typeof e == "string" && !isNaN(Number(e))) && r.push(f(e));
390
+ e == null || e === "" || typeof e == "boolean" || A(e) && a.push(f(e));
391
391
  },
392
392
  this.at
393
- ), n.length !== r.length || n.length < 2)
393
+ ), n.length !== a.length || n.length < 2)
394
394
  throw new d("#N/A", "CORREL requires two ranges of equal length with at least 2 values.");
395
- return [n, r];
395
+ return [n, a];
396
396
  }
397
397
  main(t, n) {
398
- const r = t.length, e = t.reduce((l, h) => l + h, 0) / r, a = n.reduce((l, h) => l + h, 0) / r;
398
+ const a = t.length, e = t.reduce((l, h) => l + h, 0) / a, r = n.reduce((l, h) => l + h, 0) / a;
399
399
  let i = 0, c = 0, o = 0;
400
- for (let l = 0; l < r; l++) {
401
- const h = t[l] - e, p = n[l] - a;
400
+ for (let l = 0; l < a; l++) {
401
+ const h = t[l] - e, p = n[l] - r;
402
402
  i += h * p, c += h * h, o += p * p;
403
403
  }
404
404
  const s = Math.sqrt(c * o);
@@ -407,10 +407,10 @@ class j extends y {
407
407
  return i / s;
408
408
  }
409
409
  }
410
- const H = "Returns the sample covariance, the average of the products of deviations for each data point pair in two datasets.";
411
- class J extends y {
410
+ const J = "Returns the sample covariance, the average of the products of deviations for each data point pair in two datasets.";
411
+ class Z extends x {
412
412
  constructor() {
413
- super(...arguments), this.example = "COVARIANCE.S(A1:A100, B1:B100)", this.description = H, this.defs = [
413
+ super(...arguments), this.example = "COVARIANCE.S(A1:A100, B1:B100)", this.description = J, this.defs = [
414
414
  {
415
415
  name: "data_y",
416
416
  description: "The range representing the first dataset.",
@@ -426,32 +426,32 @@ class J extends y {
426
426
  ], this.category = "statistics";
427
427
  }
428
428
  validate(t) {
429
- const n = [], r = [];
429
+ const n = [], a = [];
430
430
  if (m(
431
431
  t[0],
432
432
  (e) => {
433
- e == null || e === "" || typeof e == "boolean" || (typeof e == "number" || typeof e == "string" && !isNaN(Number(e))) && n.push(f(e));
433
+ e == null || e === "" || typeof e == "boolean" || A(e) && n.push(f(e));
434
434
  },
435
435
  this.at
436
436
  ), m(
437
437
  t[1],
438
438
  (e) => {
439
- e == null || e === "" || typeof e == "boolean" || (typeof e == "number" || typeof e == "string" && !isNaN(Number(e))) && r.push(f(e));
439
+ e == null || e === "" || typeof e == "boolean" || A(e) && a.push(f(e));
440
440
  },
441
441
  this.at
442
- ), n.length !== r.length || n.length < 2)
442
+ ), n.length !== a.length || n.length < 2)
443
443
  throw new d("#N/A", "COVARIANCE.S requires two ranges of equal length with at least 2 values.");
444
- return [n, r];
444
+ return [n, a];
445
445
  }
446
446
  main(t, n) {
447
- const r = t.length, e = t.reduce((i, c) => i + c, 0) / r, a = n.reduce((i, c) => i + c, 0) / r;
448
- return t.reduce((i, c, o) => i + (c - e) * (n[o] - a), 0) / (r - 1);
447
+ const a = t.length, e = t.reduce((i, c) => i + c, 0) / a, r = n.reduce((i, c) => i + c, 0) / a;
448
+ return t.reduce((i, c, o) => i + (c - e) * (n[o] - r), 0) / (a - 1);
449
449
  }
450
450
  }
451
- const Z = "Returns the population covariance, the average of the products of deviations for each data point pair in two datasets.";
452
- class z extends y {
451
+ const z = "Returns the population covariance, the average of the products of deviations for each data point pair in two datasets.";
452
+ class ee extends x {
453
453
  constructor() {
454
- super(...arguments), this.example = "COVARIANCE.P(A1:A100, B1:B100)", this.description = Z, this.defs = [
454
+ super(...arguments), this.example = "COVARIANCE.P(A1:A100, B1:B100)", this.description = z, this.defs = [
455
455
  {
456
456
  name: "data_y",
457
457
  description: "The range representing the first dataset.",
@@ -467,32 +467,32 @@ class z extends y {
467
467
  ], this.category = "statistics";
468
468
  }
469
469
  validate(t) {
470
- const n = [], r = [];
470
+ const n = [], a = [];
471
471
  if (m(
472
472
  t[0],
473
473
  (e) => {
474
- e == null || e === "" || typeof e == "boolean" || (typeof e == "number" || typeof e == "string" && !isNaN(Number(e))) && n.push(f(e));
474
+ e == null || e === "" || typeof e == "boolean" || A(e) && n.push(f(e));
475
475
  },
476
476
  this.at
477
477
  ), m(
478
478
  t[1],
479
479
  (e) => {
480
- e == null || e === "" || typeof e == "boolean" || (typeof e == "number" || typeof e == "string" && !isNaN(Number(e))) && r.push(f(e));
480
+ e == null || e === "" || typeof e == "boolean" || A(e) && a.push(f(e));
481
481
  },
482
482
  this.at
483
- ), n.length !== r.length || n.length < 1)
483
+ ), n.length !== a.length || n.length < 1)
484
484
  throw new d("#N/A", "COVARIANCE.P requires two ranges of equal length with at least 1 value.");
485
- return [n, r];
485
+ return [n, a];
486
486
  }
487
487
  main(t, n) {
488
- const r = t.length, e = t.reduce((i, c) => i + c, 0) / r, a = n.reduce((i, c) => i + c, 0) / r;
489
- return t.reduce((i, c, o) => i + (c - e) * (n[o] - a), 0) / r;
488
+ const a = t.length, e = t.reduce((i, c) => i + c, 0) / a, r = n.reduce((i, c) => i + c, 0) / a;
489
+ return t.reduce((i, c, o) => i + (c - e) * (n[o] - r), 0) / a;
490
490
  }
491
491
  }
492
- const ee = "Returns the most commonly occurring value in a dataset. If there are multiple modes, the smallest is returned.";
493
- class te extends y {
492
+ const te = "Returns the most commonly occurring value in a dataset. If there are multiple modes, the smallest is returned.";
493
+ class ne extends x {
494
494
  constructor() {
495
- super(...arguments), this.example = "MODE.SNGL(A1:A100)", this.description = ee, this.defs = [
495
+ super(...arguments), this.example = "MODE.SNGL(A1:A100)", this.description = te, this.defs = [
496
496
  {
497
497
  name: "value",
498
498
  description: "Numbers or ranges to compute the mode of.",
@@ -504,11 +504,11 @@ class te extends y {
504
504
  }
505
505
  validate(t) {
506
506
  const n = [];
507
- for (const r of t)
507
+ for (const a of t)
508
508
  m(
509
- r,
509
+ a,
510
510
  (e) => {
511
- e == null || e === "" || typeof e == "boolean" || (typeof e == "number" || typeof e == "string" && !isNaN(Number(e))) && n.push(f(e));
511
+ e == null || e === "" || typeof e == "boolean" || A(e) && n.push(f(e));
512
512
  },
513
513
  this.at
514
514
  );
@@ -518,19 +518,19 @@ class te extends y {
518
518
  }
519
519
  main(t) {
520
520
  const n = /* @__PURE__ */ new Map();
521
- for (const a of t)
522
- n.set(a, (n.get(a) ?? 0) + 1);
523
- const r = Math.max(...n.values());
524
- if (r < 2)
521
+ for (const r of t)
522
+ n.set(r, (n.get(r) ?? 0) + 1);
523
+ const a = Math.max(...n.values());
524
+ if (a < 2)
525
525
  throw new d("#N/A", "No value appears more than once.");
526
- const e = [...n.entries()].filter(([, a]) => a === r).map(([a]) => a);
526
+ const e = [...n.entries()].filter(([, r]) => r === a).map(([r]) => r);
527
527
  return Math.min(...e);
528
528
  }
529
529
  }
530
- const ne = "Returns the square of the Pearson product-moment correlation coefficient (R²).";
531
- class re extends y {
530
+ const ae = "Returns the square of the Pearson product-moment correlation coefficient (R²).";
531
+ class re extends x {
532
532
  constructor() {
533
- super(...arguments), this.example = "RSQ(A1:A10, B1:B10)", this.description = ne, this.defs = [
533
+ super(...arguments), this.example = "RSQ(A1:A10, B1:B10)", this.description = ae, this.defs = [
534
534
  {
535
535
  name: "data_y",
536
536
  description: "The range representing the dependent data.",
@@ -546,30 +546,30 @@ class re extends y {
546
546
  ], this.category = "statistics";
547
547
  }
548
548
  validate(t) {
549
- const n = [], r = [];
549
+ const n = [], a = [];
550
550
  if (m(
551
551
  t[0],
552
552
  (e) => {
553
- e == null || e === "" || typeof e == "boolean" || (typeof e == "number" || typeof e == "string" && !isNaN(Number(e))) && n.push(f(e));
553
+ e == null || e === "" || typeof e == "boolean" || A(e) && n.push(f(e));
554
554
  },
555
555
  this.at
556
556
  ), m(
557
557
  t[1],
558
558
  (e) => {
559
- e == null || e === "" || typeof e == "boolean" || (typeof e == "number" || typeof e == "string" && !isNaN(Number(e))) && r.push(f(e));
559
+ e == null || e === "" || typeof e == "boolean" || A(e) && a.push(f(e));
560
560
  },
561
561
  this.at
562
- ), n.length !== r.length)
562
+ ), n.length !== a.length)
563
563
  throw new d("#N/A", "RSQ requires two ranges of equal length.");
564
564
  if (n.length < 2)
565
565
  throw new d("#N/A", "RSQ requires at least 2 data points.");
566
- return [n, r];
566
+ return [n, a];
567
567
  }
568
568
  main(t, n) {
569
- const r = t.length, e = t.reduce((h, p) => h + p, 0) / r, a = n.reduce((h, p) => h + p, 0) / r;
569
+ const a = t.length, e = t.reduce((h, p) => h + p, 0) / a, r = n.reduce((h, p) => h + p, 0) / a;
570
570
  let i = 0, c = 0, o = 0;
571
- for (let h = 0; h < r; h++) {
572
- const p = t[h] - e, g = n[h] - a;
571
+ for (let h = 0; h < a; h++) {
572
+ const p = t[h] - e, g = n[h] - r;
573
573
  i += p * g, c += p * p, o += g * g;
574
574
  }
575
575
  const s = Math.sqrt(c * o);
@@ -579,20 +579,20 @@ class re extends y {
579
579
  return l * l;
580
580
  }
581
581
  }
582
- const ae = `Returns the probability associated with a Student's t-test.
582
+ const se = `Returns the probability associated with a Student's t-test.
583
583
  tails: 1 (one-tailed) or 2 (two-tailed).
584
584
  type: 1 (paired), 2 (two-sample equal variance), 3 (two-sample unequal variance).`;
585
- function E(u, t, n) {
585
+ function q(u, t, n) {
586
586
  if (u <= 0)
587
587
  return 0;
588
588
  if (u >= 1)
589
589
  return 1;
590
590
  if (u > (t + 1) / (t + n + 2))
591
- return 1 - E(1 - u, n, t);
592
- const r = x(t) + x(n) - x(t + n), e = Math.exp(Math.log(u) * t + Math.log(1 - u) * n - r) / t, a = 200, i = 3e-7;
591
+ return 1 - q(1 - u, n, t);
592
+ const a = M(t) + M(n) - M(t + n), e = Math.exp(Math.log(u) * t + Math.log(1 - u) * n - a) / t, r = 200, i = 3e-7;
593
593
  let c = 1, o = 1, s = 1 - (t + n) * u / (t + 1);
594
594
  Math.abs(s) < 1e-30 && (s = 1e-30), s = 1 / s, c = s;
595
- for (let l = 1; l <= a; l++) {
595
+ for (let l = 1; l <= r; l++) {
596
596
  let h = l * (n - l) * u / ((t + 2 * l - 1) * (t + 2 * l));
597
597
  s = 1 + h * s, Math.abs(s) < 1e-30 && (s = 1e-30), o = 1 + h / o, Math.abs(o) < 1e-30 && (o = 1e-30), s = 1 / s, c *= s * o, h = -(t + l) * (t + n + l) * u / ((t + 2 * l) * (t + 2 * l + 1)), s = 1 + h * s, Math.abs(s) < 1e-30 && (s = 1e-30), o = 1 + h / o, Math.abs(o) < 1e-30 && (o = 1e-30), s = 1 / s;
598
598
  const p = s * o;
@@ -601,7 +601,7 @@ function E(u, t, n) {
601
601
  }
602
602
  return e * c;
603
603
  }
604
- function x(u) {
604
+ function M(u) {
605
605
  const n = [
606
606
  0.9999999999998099,
607
607
  676.5203681218851,
@@ -614,21 +614,21 @@ function x(u) {
614
614
  15056327351493116e-23
615
615
  ];
616
616
  if (u < 0.5)
617
- return Math.log(Math.PI / Math.sin(Math.PI * u)) - x(1 - u);
617
+ return Math.log(Math.PI / Math.sin(Math.PI * u)) - M(1 - u);
618
618
  u--;
619
- let r = n[0];
620
- for (let a = 1; a < 9; a++)
621
- r += n[a] / (u + a);
619
+ let a = n[0];
620
+ for (let r = 1; r < 9; r++)
621
+ a += n[r] / (u + r);
622
622
  const e = u + 7 + 0.5;
623
- return 0.5 * Math.log(2 * Math.PI) + (u + 0.5) * Math.log(e) - e + Math.log(r);
623
+ return 0.5 * Math.log(2 * Math.PI) + (u + 0.5) * Math.log(e) - e + Math.log(a);
624
624
  }
625
- function se(u, t) {
625
+ function ie(u, t) {
626
626
  const n = t / (t + u * u);
627
- return E(n, t / 2, 0.5);
627
+ return q(n, t / 2, 0.5);
628
628
  }
629
- class ie extends y {
629
+ class oe extends x {
630
630
  constructor() {
631
- super(...arguments), this.example = "T.TEST(A1:A100, B1:B100, 2, 2)", this.description = ae, this.defs = [
631
+ super(...arguments), this.example = "T.TEST(A1:A100, B1:B100, 2, 2)", this.description = se, this.defs = [
632
632
  { name: "range1", description: "The first sample of data.", takesMatrix: !0, acceptedTypes: ["matrix"] },
633
633
  { name: "range2", description: "The second sample of data.", takesMatrix: !0, acceptedTypes: ["matrix"] },
634
634
  { name: "tails", description: "The number of distribution tails: 1 or 2.", acceptedTypes: ["number"] },
@@ -640,12 +640,12 @@ class ie extends y {
640
640
  ], this.category = "statistics";
641
641
  }
642
642
  validate(t) {
643
- const n = Math.floor(f(t[2])), r = Math.floor(f(t[3]));
643
+ const n = Math.floor(f(t[2])), a = Math.floor(f(t[3]));
644
644
  if (n !== 1 && n !== 2)
645
645
  throw new d("#NUM!", "tails must be 1 or 2.");
646
- if (r < 1 || r > 3)
646
+ if (a < 1 || a > 3)
647
647
  throw new d("#NUM!", "type must be 1, 2, or 3.");
648
- const e = [], a = [];
648
+ const e = [], r = [];
649
649
  if (m(
650
650
  t[0],
651
651
  (i) => {
@@ -655,33 +655,33 @@ class ie extends y {
655
655
  ), m(
656
656
  t[1],
657
657
  (i) => {
658
- i == null || i === "" || typeof i == "boolean" || a.push(f(i));
658
+ i == null || i === "" || typeof i == "boolean" || r.push(f(i));
659
659
  },
660
660
  this.at
661
- ), r === 1) {
662
- if (e.length !== a.length || e.length < 2)
661
+ ), a === 1) {
662
+ if (e.length !== r.length || e.length < 2)
663
663
  throw new d("#N/A", "Paired T.TEST requires equal-length ranges with at least 2 values.");
664
- } else if (e.length < 2 || a.length < 2)
665
- throw new d("#DIV/0!", `T.TEST type ${r} requires at least 2 values per range.`);
666
- return [e, a, n, r];
664
+ } else if (e.length < 2 || r.length < 2)
665
+ throw new d("#DIV/0!", `T.TEST type ${a} requires at least 2 values per range.`);
666
+ return [e, r, n, a];
667
667
  }
668
- main(t, n, r, e) {
669
- let a, i;
668
+ main(t, n, a, e) {
669
+ let r, i;
670
670
  if (e === 1) {
671
671
  const o = t.map((p, g) => p - n[g]), s = o.length, l = o.reduce((p, g) => p + g, 0) / s, h = o.reduce((p, g) => p + (g - l) ** 2, 0) / (s - 1);
672
- a = l / Math.sqrt(h / s), i = s - 1;
672
+ r = l / Math.sqrt(h / s), i = s - 1;
673
673
  } else if (e === 2) {
674
- const o = t.reduce((g, A) => g + A, 0) / t.length, s = n.reduce((g, A) => g + A, 0) / n.length, l = t.reduce((g, A) => g + (A - o) ** 2, 0) / (t.length - 1), h = n.reduce((g, A) => g + (A - s) ** 2, 0) / (n.length - 1), p = ((t.length - 1) * l + (n.length - 1) * h) / (t.length + n.length - 2);
675
- a = (o - s) / Math.sqrt(p * (1 / t.length + 1 / n.length)), i = t.length + n.length - 2;
674
+ const o = t.reduce((g, w) => g + w, 0) / t.length, s = n.reduce((g, w) => g + w, 0) / n.length, l = t.reduce((g, w) => g + (w - o) ** 2, 0) / (t.length - 1), h = n.reduce((g, w) => g + (w - s) ** 2, 0) / (n.length - 1), p = ((t.length - 1) * l + (n.length - 1) * h) / (t.length + n.length - 2);
675
+ r = (o - s) / Math.sqrt(p * (1 / t.length + 1 / n.length)), i = t.length + n.length - 2;
676
676
  } else {
677
- const o = t.reduce((A, N) => A + N, 0) / t.length, s = n.reduce((A, N) => A + N, 0) / n.length, l = t.reduce((A, N) => A + (N - o) ** 2, 0) / (t.length - 1), h = n.reduce((A, N) => A + (N - s) ** 2, 0) / (n.length - 1), p = l / t.length, g = h / n.length;
678
- a = (o - s) / Math.sqrt(p + g), i = (p + g) ** 2 / (p ** 2 / (t.length - 1) + g ** 2 / (n.length - 1));
677
+ const o = t.reduce((w, y) => w + y, 0) / t.length, s = n.reduce((w, y) => w + y, 0) / n.length, l = t.reduce((w, y) => w + (y - o) ** 2, 0) / (t.length - 1), h = n.reduce((w, y) => w + (y - s) ** 2, 0) / (n.length - 1), p = l / t.length, g = h / n.length;
678
+ r = (o - s) / Math.sqrt(p + g), i = (p + g) ** 2 / (p ** 2 / (t.length - 1) + g ** 2 / (n.length - 1));
679
679
  }
680
- const c = se(Math.abs(a), i);
681
- return r === 1 ? c / 2 : c;
680
+ const c = ie(Math.abs(r), i);
681
+ return a === 1 ? c / 2 : c;
682
682
  }
683
683
  }
684
- const ce = {
684
+ const ue = {
685
685
  averageif: S,
686
686
  averageifs: V,
687
687
  median: C,
@@ -690,17 +690,17 @@ const ce = {
690
690
  "var.s": _,
691
691
  "var.p": Q,
692
692
  "percentile.inc": O,
693
- "quartile.inc": X,
694
- "rank.eq": K,
695
- correl: j,
696
- "covariance.s": J,
697
- "covariance.p": z,
698
- "mode.sngl": te,
693
+ "quartile.inc": Y,
694
+ "rank.eq": W,
695
+ correl: H,
696
+ "covariance.s": Z,
697
+ "covariance.p": ee,
698
+ "mode.sngl": ne,
699
699
  rsq: re,
700
- "t.test": ie
700
+ "t.test": oe
701
701
  };
702
702
  export {
703
- ce as default,
704
- ce as statisticsFunctions
703
+ ue as default,
704
+ ue as statisticsFunctions
705
705
  };
706
706
  //# sourceMappingURL=index.js.map