ziko 0.53.0 → 0.54.1

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,4 +1,5 @@
1
- import { mapfun } from '../../mapfun/index.js';
1
+ import { mapfun } from '../mapfun/index.js';
2
+ import { complex } from '../../complex/index.js'
2
3
 
3
4
  export const abs = (...x) => mapfun(
4
5
  x =>{
@@ -22,7 +23,7 @@ export const pow = (...x) => {
22
23
  if(n.isComplex?.()) return new x.constructor({
23
24
  z: Math.exp(n.a * Math.log(x)),
24
25
  phi: n.b * Math.log(x)
25
- })
26
+ })
26
27
  return Math.pow(x, n)
27
28
  },
28
29
  ...x
@@ -32,7 +33,8 @@ export const pow = (...x) => {
32
33
  export const sqrt = (...x) => mapfun(
33
34
  x=>{
34
35
  if(x.isComplex?.())
35
- return new x.constructor({z: x.z**(1/2), phi: x.phi/2})
36
+ return new x.constructor({z: x.z**(1/2), phi: x.phi/2});
37
+ if(x < 0) return complex(0, Math.sqrt(-x))
36
38
  return Math.sqrt(x);
37
39
  },
38
40
  ...x
@@ -42,16 +44,18 @@ export const cbrt = (...x) => mapfun(
42
44
  x=>{
43
45
  if(x.isComplex?.())
44
46
  return new x.constructor({z: x.z**(1/3), phi: x.phi/3})
45
- return Math.sqrt(x);
47
+ return Math.cbrt(x);
46
48
  },
47
49
  ...x
48
50
  );
49
51
 
50
52
  export const nthr = (...x) => {
51
53
  const n = x.pop();
54
+ if(typeof n !== 'number') throw Error('nthr expects a real number n');
52
55
  return mapfun(
53
56
  x => {
54
- if(x.isComplex?.()) return new x.constructor({z: x.z ** 1/n, phi: x.phi / n});
57
+ if(x.isComplex?.()) return new x.constructor({z: x.z ** (1/n), phi: x.phi / n});
58
+ if(x<0) return n%2===2 ? complex(0, (-x)**(1/n)) : -1 * (-x)**(1/n)
55
59
  return x**(1/n)
56
60
  },
57
61
  ...x
@@ -59,11 +63,20 @@ export const nthr = (...x) => {
59
63
  }
60
64
 
61
65
  export const croot = (...x) =>{
62
- const z = x.pop()
66
+ const c = x.pop()
67
+ if(!c.isComplex?.()) throw Error('croot expect Complex number as root')
63
68
  return mapfun(
64
69
  x => {
65
- if(x.isComplex?.()) return null
66
- return null
70
+ if(typeof x === 'number') x = new c.constructor(x, 0);
71
+ const {a : c_a, b : c_b} = c;
72
+ const {z, phi} = x;
73
+ const D = Math.hypot(c_a, c_b);
74
+ const A = Math.exp((Math.log(z)*c_a + phi*c_b)/D);
75
+ const B = (phi*c_a - Math.log(z)*c_b)/D
76
+ return new c.constructor(
77
+ A * Math.cos(B),
78
+ A * Math.sin(B)
79
+ )
67
80
  },
68
81
  ...x
69
82
  )
@@ -75,7 +88,7 @@ export const exp = (...x) => mapfun(
75
88
  Math.exp(x.a) * Math.cos(x.b),
76
89
  Math.exp(x.a) * Math.sin(x.b)
77
90
  );
78
- return Math.ln(x)
91
+ return Math.exp(x)
79
92
  }
80
93
  ,...x
81
94
  );
@@ -86,7 +99,7 @@ export const ln = (...x) => mapfun(
86
99
  Math.log(x.z),
87
100
  x.phi
88
101
  );
89
- return Math.ln(x)
102
+ return Math.log(x)
90
103
  }
91
104
  ,...x
92
105
  );
@@ -268,33 +281,33 @@ export const acot = (...x) => mapfun(
268
281
  export const cosh = (...x) => mapfun(
269
282
  x =>{
270
283
  if(x?.isComplex) return new x.constructor(
271
- cosh(x.a)*cos(x.b),
272
- sinh(x.a)*sin(x.b)
284
+ Math.cosh(x.a) * Math.cos(x.b),
285
+ Math.sinh(x.a) * Math.sin(x.b)
273
286
  );
274
- return cosh(x)
287
+ return Math.cosh(x)
275
288
  },
276
289
  ...x
277
290
  )
278
291
  export const sinh = (...x) => mapfun(
279
292
  x =>{
280
293
  if(x?.isComplex) return new x.constructor(
281
- sinh(x.a)*cos(x.b),
282
- cosh(x.a)*sin(x.b)
294
+ Math.sinh(x.a) * Math.cos(x.b),
295
+ Math.cosh(x.a) * Math.sin(x.b)
283
296
  );
284
- return sinh(x)
297
+ return Math.sinh(x)
285
298
  },
286
299
  ...x
287
300
  )
288
301
  export const tanh = (...x) => mapfun(
289
302
  x =>{
290
303
  if(x?.isComplex){
291
- const D=cosh(2*a)+cos(2*b);
304
+ const D = Math.cosh(2*a) + Math.cos(2*b);
292
305
  return new x.constructor(
293
- sinh(2*a)/D,
294
- sin(2*b)/D
306
+ Math.sinh(2*a) / D,
307
+ Math.sin(2*b) / D
295
308
  )
296
309
  }
297
- return tanh(x)
310
+ return Math.tanh(x)
298
311
  },
299
312
  ...x
300
313
  )
@@ -349,7 +362,7 @@ export const sig = (...x) => mapfun(
349
362
  if(x?.isComplex){
350
363
 
351
364
  }
352
- return 1/(1+Math.e(-x))
365
+ return 1/(1+Math.exp(-x))
353
366
  },
354
367
  ...x
355
368
  )
@@ -0,0 +1,104 @@
1
+ import { mapfun } from "../mapfun/index.js";
2
+ import { nthr, pow } from "../nested/index.js";
3
+
4
+ export const zeros = n => new Array(n).fill(0);
5
+ export const ones = n => new Array(n).fill(1);
6
+ export const nums = (n, num) => new Array(n).fill(num);
7
+
8
+
9
+ export const arange = (a, b, step, include = false) => {
10
+ if(a instanceof Array && typeof b === 'number') return mapfun(x => arange(x, b, step, include), ...a);
11
+ if(b instanceof Array && typeof a === 'number') return mapfun(x => arange(a, x, step, include), ...b);
12
+ if(a instanceof Array && b instanceof Array){
13
+ if(a.length !== b.length) return TypeError('');
14
+ let res = new Array(a.length).fill(null)
15
+ return res.map((_, i) => arange(a[i], b[i], step, include))
16
+ }
17
+ if(typeof a === 'number' && typeof b === 'number'){
18
+ const values = [];
19
+ let i;
20
+ if(a<b){
21
+ for (i = a; include ? i<=b : i<b ; i += step)
22
+ values.push((i * 10) / 10);
23
+ }
24
+ else{
25
+ for(i = a; include ? i>=b: i>b ; i -= step)
26
+ values.push((i * 10) / 10);
27
+ }
28
+ return values
29
+ }
30
+ }
31
+
32
+ export const linspace = (a, b, n = Math.abs(b-a) + 1, endpoint = true) =>{
33
+ if(Math.floor(n) !== n) return TypeError('');
34
+ let c = [a, b].find(n => n.isComplex?.())
35
+ if(c){
36
+ let z1 = new c.constructor(a);
37
+ let z2 = new c.constructor(b)
38
+ if (!n) n = Math.abs(z1.a - z2.a) + 1;
39
+ const X = linspace(z1.a, z2.a, n, endpoint);
40
+ const Y = linspace(z1.a, z2.a, n, endpoint);
41
+ let Z = new Array(n).fill(null);
42
+ Z = Z.map((_, i) => new z1.constructor(X[i], Y[i]));
43
+ return Z;
44
+ }
45
+ if(a instanceof Array && typeof b === 'number') return mapfun(x => linspace(x, b, step, include), ...a);
46
+ if(b instanceof Array && typeof a === 'number') return mapfun(x => linspace(a, x, step, include), ...b);
47
+ if(a instanceof Array && b instanceof Array){
48
+ if(a.length !== b.length) return TypeError('');
49
+ let res = new Array(a.length).fill(null)
50
+ return res.map((_, i) => linspace(a[i], b[i], step, include))
51
+ }
52
+ if(typeof a === 'number' && typeof b === 'number'){
53
+ const [max, min] = [a, b].sort((a, b) => b-a);
54
+ let Y = [], step, i;
55
+ endpoint ? step = (max - min) / (n - 1) : step = (max - min) / n;
56
+ if(a < b)
57
+ for(i = 0; i < n; i++)
58
+ Y.push(+(min + step * i).toFixed(8))
59
+ else
60
+ for(i = 0; i < n; i++)
61
+ Y.push(+(max - step * i).toFixed(8))
62
+ return Y
63
+ }
64
+ }
65
+
66
+ export const logspace = (a, b, n = Math.abs(b-a) + 1, base = Math.E, endpoint = true) => {
67
+ const ls = linspace(a, b, n, endpoint);
68
+ return mapfun(x => pow(base, x), ...ls)
69
+ }
70
+
71
+ export const geomspace = (a, b, n = Math.abs(b-a) + 1, endpoint = true, precison = 8) =>{
72
+ if(Math.floor(n) !== n) return TypeError('n must be and integer');
73
+ let c = [a, b].find(n => n.isComplex?.())
74
+ if(c){
75
+ let z1 = new c.constructor(a);
76
+ let z2 = new c.constructor(b);
77
+ if (!n) n = Math.abs(z1.a - z2.a) + 1;
78
+ const ratio = nthr(z2.clone().div(z1.clone()), n-1);
79
+ let i;
80
+ const Y = [];
81
+ for(i = 0; i < n; i++){
82
+ Y[i] = z1.clone().mul(pow(ratio.clone(), i))
83
+ }
84
+
85
+ return Y.map(n => n.toFixed(precison))
86
+ }
87
+ if(a instanceof Array && typeof b === 'number') return mapfun(x => geomspace(x, b, n, endpoint, precison), ...a);
88
+ if(b instanceof Array && typeof a === 'number') return mapfun(x => geomspace(a, x, n, endpoint, precison), ...b);
89
+ if(a instanceof Array && b instanceof Array){
90
+ if(a.length !== b.length) return TypeError('');
91
+ let res = new Array(a.length).fill(null)
92
+ return res.map((_, i) => geomspace(a[i], b[i], n, endpoint, precison))
93
+ }
94
+ if(typeof a === 'number' && typeof b === 'number'){
95
+ const [max, min]= [a, b].sort((a, b) => b-a);
96
+ let base = endpoint ? nthr(max/min, n-1) : nthr(max/min, n);
97
+ const Y = [min];
98
+ let i;
99
+ for(i = 1; i < n; i++)
100
+ Y.push(Y[i-1] * base )
101
+ const Fixed = Y.map(n => + n.toFixed(precison))
102
+ return a < b ? Fixed : Fixed.reverse()
103
+ }
104
+ }
@@ -0,0 +1,49 @@
1
+ import {add, mul} from '../arithmetic/index.js';
2
+
3
+ export const min = (...x) => Math.min(...x);
4
+ export const max = (...x) => Math.max(...x);
5
+
6
+ export const mean = (...x) => x.reduce((a, b) => a + b) / x.length;
7
+
8
+ export const variance = (...x) => {
9
+ const n = x.length;
10
+ if (n === 0) return NaN;
11
+ const x_mean = mean(...x);
12
+ return x.reduce((sum, xi) => sum + (xi - x_mean) ** 2, 0) / n;
13
+ };
14
+
15
+ export const std = (...x) => Math.sqrt(variance(...x));
16
+
17
+ export const accum_sum = (...x) => {
18
+ let result = [];
19
+ let total = 0, i; n = x.length;
20
+ for(i = 0; i < n ; i++){
21
+ total = add(total, x[i])
22
+ result.push(total);
23
+ }
24
+ return result;
25
+ };
26
+
27
+ export const accum_prod = (...x) => {
28
+ let result = [];
29
+ let prod = 1, i; n = x.length;
30
+ for(i = 0; i < n ; i++){
31
+ prod = mul(prod, x[i])
32
+ result.push(prod);
33
+ }
34
+ return result;
35
+ };
36
+
37
+ export const percentile = (X, p) => {
38
+ if (X.length === 0)
39
+ return NaN;
40
+ let a = [...X].sort((x, y) => x - y);
41
+ let index = (p / 100) * (a.length - 1);
42
+ let i = Math.floor(index);
43
+ let f = index - i;
44
+ if (i === a.length - 1)
45
+ return a[i];
46
+ return a[i] * (1 - f) + a[i + 1] * f;
47
+ }
48
+
49
+ export const median = X => percentile(X, 50);
@@ -0,0 +1,105 @@
1
+ import { mapfun, apply_fun } from "../mapfun/index.js";
2
+
3
+ export const deg2rad = (...deg) => mapfun(x => x * Math.PI / 180, ...deg);
4
+ export const rad2deg = (...rad) => mapfun(x => x / Math.PI * 180, ...rad);
5
+
6
+ export const norm = (x, min, max) => apply_fun(
7
+ x,
8
+ v => min !== max ? (v - min) / (max - min) : 0
9
+ );
10
+ export const lerp = (x, min, max) => apply_fun(
11
+ x,
12
+ v => (max - min) * v + min
13
+ );
14
+ export const clamp = (x, min, max) => apply_fun(
15
+ x,
16
+ v => Math.min(Math.max(v, min), max)
17
+ );
18
+ export const map = (x, a, b, c, d) => apply_fun(
19
+ x,
20
+ v => lerp(norm(v, a, b), c, d)
21
+ );
22
+
23
+
24
+ // export const norm = (x, min, max) => {
25
+ // if(x.isComplex?.()) return new x.constructor(
26
+ // norm(x.a, min, max),
27
+ // norm(x.b, min, max)
28
+ // )
29
+ // if(x.isMatrix?.()) return new x.constructor(
30
+ // x.rows,
31
+ // x.cols,
32
+ // norm(x.arr.flat(1), min, max)
33
+ // );
34
+ // if(x instanceof Array) return mapfun(n => norm(n, min, max), ...x);
35
+ // return min !== max ? (x - min) / (max - min) : 0;
36
+ // }
37
+
38
+
39
+ // export const lerp = (x, min, max) => {
40
+ // if(x.isComplex?.()) return new x.constructor(
41
+ // lerp(x.a, min, max),
42
+ // lerp(x.b, min, max)
43
+ // )
44
+ // if(x.isMatrix?.()) return new x.constructor(
45
+ // x.rows,
46
+ // x.cols,
47
+ // lerp(x.arr.flat(1), min, max)
48
+ // );
49
+ // if(x instanceof Array) return mapfun(n => lerp(n, min, max), ...x);
50
+ // return (max - min) * x + min;
51
+ // }
52
+
53
+ // export const map = (x, a, b, c, d) => {
54
+ // if(x.isComplex?.()) return new x.constructor(
55
+ // map(x.a, a, b, c, d),
56
+ // map(x.b, a, b, c, d)
57
+ // )
58
+ // if(x.isMatrix?.()) return new x.constructor(
59
+ // x.rows,
60
+ // x.cols,
61
+ // map(x.arr.flat(1), a, b, c, d)
62
+ // );
63
+ // if(x instanceof Array) return mapfun(n => map(n, a, b, c, d), ...x);
64
+ // return lerp(norm(x, a, b), c, d);
65
+ // }
66
+
67
+ // export const clamp = (x, min, max) => {
68
+ // if(x.isComplex?.()) return new x.constructor(
69
+ // clamp(x.a, min, max),
70
+ // clamp(x.b, min, max)
71
+ // )
72
+ // if(x.isMatrix?.()) return new x.constructor(
73
+ // x.rows,
74
+ // x.cols,
75
+ // clamp(x.arr.flat(1), min, max)
76
+ // );
77
+ // if(x instanceof Array) return mapfun(n => clamp(n, min, max), ...x);
78
+ // return Math.min(Math.max(x, min), max)
79
+ // }
80
+
81
+ export const hypot = (...x) => {
82
+ const c0 = x.find(a => a.isComplex?.());
83
+ if (c0) {
84
+ const W = x.map(n => n.isComplex?.() ? n : new c0.constructor(n, 0));
85
+ return Math.hypot(...W.map(c => c.z));
86
+ }
87
+ return Math.hypot(...x);
88
+ };
89
+
90
+
91
+ export const atan2 = (y, x, rad = true) => {
92
+ if (y instanceof Array && !(x instanceof Array))
93
+ return mapfun(n => atan2(n, x, rad), ...y);
94
+
95
+ if (x instanceof Array && !(y instanceof Array))
96
+ return mapfun(n => atan2(y, n, rad), ...x);
97
+
98
+ if (y instanceof Array && x instanceof Array)
99
+ return y.map((v, i) => atan2(v, x[i], rad));
100
+
101
+ const phi = Math.atan2(y, x);
102
+ return rad ? phi : phi * 180 / Math.PI;
103
+ }
104
+
105
+
@@ -1,4 +1,4 @@
1
- import { add, sub, mul } from "../../utils/index.js";
1
+ import { add, sub, mul } from "../../functions/arithmetic/index.js";
2
2
  import { pow } from "../../functions/index.js";
3
3
  export function matrix_det(M) {
4
4
  if (!M.isSquare) return new Error("is not square matrix");
@@ -1,22 +1,17 @@
1
- import{
2
- min,
3
- max,
4
- } from "../functions/index.js"
5
- import {
6
- Utils,
1
+ import {
7
2
  add,
8
3
  sub,
9
4
  mul,
10
- div,
11
- modulo,
5
+ div,
6
+ modulo
7
+ } from '../functions/arithmetic/index.js'
8
+ import {
12
9
  map,
13
- lerp,
14
- norm,
15
- clamp
16
-
17
- } from "../utils/index.js";
10
+ lerp,
11
+ clamp,
12
+ norm
13
+ } from '../functions/utils/index.js'
18
14
  import { Complex } from "../complex/index.js";
19
- // import { Random } from "../random/index.js"
20
15
  import { arr2str } from "../../data/index.js";
21
16
  import {
22
17
  matrix_inverse,
@@ -1,70 +1,10 @@
1
- import { abs , pow , sqrtn , max , min} from "../functions/index.js";
2
- import { mul } from "../utils/index.js";
1
+ import { abs , pow , nthr } from "../functions/index.js";
2
+ import { mul } from "../functions/arithmetic/index.js";
3
3
  import { E } from "../const.js";
4
4
  const zeros=(n)=>new Array(n).fill(0);
5
5
  const ones=(n)=>new Array(n).fill(1);
6
6
  const nums=(num,n)=>new Array(n).fill(num);
7
- const norm=(value, min, max)=>{
8
- if (typeof value === "number") return min !== max ? (value - min) / (max - min) : 0;
9
- else if (value.isMatrix?.()) return new value.constructor(value.rows, value.cols, norm(value.arr.flat(1), min, max));
10
- else if (value.isComplex?.()) return new value.constructor(norm(value.a, min, max), norm(value.b, min, max));
11
- else if (value instanceof Array) {
12
- if (value.every((n) => typeof (n === "number"))) {
13
- return value.map((n) => norm(n, min, max));
14
- } else {
15
- let y = new Array(value.length);
16
- for (let i = 0; i < value.length; i++) {
17
- y[i] = norm(value[i]);
18
- }
19
- }
20
- }
21
- }
22
- const lerp=(value, min, max)=>{
23
- if (typeof value === "number") return (max - min) * value + min;
24
- else if (value.isMatrix?.()) return new value.constructor(value.rows, value.cols, lerp(value.arr.flat(1), min, max));
25
- else if (value.isComplex?.()) return new value.constructor(lerp(value.a, min, max), lerp(value.b, min, max));
26
- else if (value instanceof Array) {
27
- if (value.every((n) => typeof (n === "number"))) {
28
- return value.map((n) => lerp(n, min, max));
29
- } else {
30
- let y = new Array(value.length);
31
- for (let i = 0; i < value.length; i++) {
32
- y[i] = lerp(value[i]);
33
- }
34
- }
35
- }
36
- }
37
- const map=(x, a, b, c, d)=>{
38
- if (typeof x === "number") return lerp(norm(x, a, b), c, d);
39
- else if (x.isMatrix?.()) return new x.constructor(x.rows, x.cols, map(x.arr.flat(1), a, b, c, d));
40
- else if (x.isComplex?.()) return new x.constructor(map(x.a, b, c, d), map(x.b, a, b, c, d));
41
- else if (x instanceof Array) {
42
- if (x.every((n) => typeof (n === "number"))) {
43
- return x.map((n) => map(n, a, b, c, d));
44
- } else {
45
- let y = new Array(x.length);
46
- for (let i = 0; i < x.length; i++) {
47
- y[i] = map(x[i], a, b, c, d);
48
- }
49
- }
50
- }
51
- }
52
- const clamp=(x, a , b)=>{
53
- const [min_value,max_value]=[min(a,b),max(a,b)]
54
- if (typeof x === "number") return min(max(x, min_value), max_value);
55
- else if (x.isMatrix?.()) return new x.constructor(x.rows, x.cols, clamp(x.arr.flat(1), min_value, max_value));
56
- else if (x.isComplex?.()) return new x.constructor(clamp(x.a, min_value, max_value), clamp(x.b, min_value, max_value));
57
- else if (x instanceof Array) {
58
- if (x.every((n) => typeof (n === "number"))) {
59
- return x.map((n) => clamp(n, min_value, max_value));
60
- } else {
61
- let y = new Array(x.length);
62
- for (let i = 0; i < x.length; i++) {
63
- y[i] = clamp(x[i], min_value, max_value);
64
- }
65
- }
66
- }
67
- }
7
+
68
8
  const arange=(a, b, step , include = false)=>{
69
9
  let tab = [];
70
10
  if(a<b){
@@ -107,7 +47,7 @@ const geomspace=(a,b,n=abs(b-a)+1,endpoint=true)=>{
107
47
  if([a,b].every(n=>typeof n==="number")){
108
48
  const [max,min]=[a,b].sort((a,b)=>b-a);
109
49
  let base;
110
- endpoint ? base = sqrtn(max/min,n-1) : base = sqrtn(max/min,n) ;
50
+ endpoint ? base = nthr(max/min,n-1) : base = nthr(max/min,n) ;
111
51
  const Y = [min];
112
52
  for (let i = 1; i < n; i++) {
113
53
  Y.push(Y[i-1]*base)
@@ -120,7 +60,7 @@ const geomspace=(a,b,n=abs(b-a)+1,endpoint=true)=>{
120
60
  const z2 = new n.constructor(b)
121
61
  n=n||Math.abs(z1.a-z2.a)+1;
122
62
  let base;
123
- endpoint ? base = sqrtn(z2.div(z1),n-1) : base = sqrtn(z2.div(z1),n) ;
63
+ endpoint ? base = nthr(z2.div(z1),n-1) : base = nthr(z2.div(z1),n) ;
124
64
  const Y = [z1];
125
65
  for (let i = 1; i < n; i++) {
126
66
  Y.push(mul(Y[i-1],base))
@@ -132,10 +72,10 @@ export {
132
72
  zeros,
133
73
  ones,
134
74
  nums,
135
- norm,
136
- lerp,
137
- map,
138
- clamp,
75
+ // norm,
76
+ // lerp,
77
+ // map,
78
+ // clamp,
139
79
  arange,
140
80
  linspace,
141
81
  logspace,
@@ -29,36 +29,36 @@ const prod=(...x)=>{
29
29
  }
30
30
  return Y.length===1?Y[0]:Y;
31
31
  }
32
- const min=(...num)=>{
33
- if(num.every(n=>typeof n==="number"))return Math.min(...num);
34
- const Y=[];
35
- for(let i=0;i<num.length;i++){
36
- if(num[i] instanceof Array)Y.push(min(...num[i]));
37
- else if(num[i] instanceof Object){
38
- Y.push(
39
- Object.fromEntries(
40
- [Object.entries(num[i]).sort((a,b)=>a[1]-b[1])[0]]
41
- )
42
- )
43
- }
44
- }
45
- return Y.length===1?Y[0]:Y;
46
- }
47
- const max=(...num)=>{
48
- if(num.every(n=>typeof n==="number"))return Math.max(...num);
49
- const Y=[];
50
- for(let i=0;i<num.length;i++){
51
- if(num[i] instanceof Array)Y.push(min(...num[i]));
52
- else if(num[i] instanceof Object){
53
- Y.push(
54
- Object.fromEntries(
55
- [Object.entries(num[i]).sort((a,b)=>b[1]-a[1])[0]]
56
- )
57
- )
58
- }
59
- }
60
- return Y.length===1?Y[0]:Y;
61
- }
32
+ // const min=(...num)=>{
33
+ // if(num.every(n=>typeof n==="number"))return Math.min(...num);
34
+ // const Y=[];
35
+ // for(let i=0;i<num.length;i++){
36
+ // if(num[i] instanceof Array)Y.push(min(...num[i]));
37
+ // else if(num[i] instanceof Object){
38
+ // Y.push(
39
+ // Object.fromEntries(
40
+ // [Object.entries(num[i]).sort((a,b)=>a[1]-b[1])[0]]
41
+ // )
42
+ // )
43
+ // }
44
+ // }
45
+ // return Y.length===1?Y[0]:Y;
46
+ // }
47
+ // const max=(...num)=>{
48
+ // if(num.every(n=>typeof n==="number"))return Math.max(...num);
49
+ // const Y=[];
50
+ // for(let i=0;i<num.length;i++){
51
+ // if(num[i] instanceof Array)Y.push(min(...num[i]));
52
+ // else if(num[i] instanceof Object){
53
+ // Y.push(
54
+ // Object.fromEntries(
55
+ // [Object.entries(num[i]).sort((a,b)=>b[1]-a[1])[0]]
56
+ // )
57
+ // )
58
+ // }
59
+ // }
60
+ // return Y.length===1?Y[0]:Y;
61
+ // }
62
62
  const accum=(...num)=>{
63
63
  if(num.every(n=>typeof n==="number")){
64
64
  let acc = num.reduce((x, y) => [...x, x[x.length - 1] + y], [0]);
@@ -84,8 +84,8 @@ const accum=(...num)=>{
84
84
  export{
85
85
  sum,
86
86
  prod,
87
- min,
88
- max,
87
+ // min,
88
+ // max,
89
89
  accum
90
90
  }
91
91
 
@@ -1,15 +1,15 @@
1
1
  import {
2
2
  sum,
3
3
  prod,
4
- min,
5
- max,
4
+ // min,
5
+ // max,
6
6
  accum
7
7
  } from "./functions/index.js"
8
8
  const Stats={
9
9
  sum,
10
10
  prod,
11
- min,
12
- max,
11
+ // min,
12
+ // max,
13
13
  accum,
14
14
  }
15
15
  export default Stats;
@@ -0,0 +1,39 @@
1
+ export const accum_sum = (arr) => {
2
+ let result = [];
3
+ let total = 0;
4
+ for (let x of arr) {
5
+ total += x;
6
+ result.push(total);
7
+ }
8
+ return result;
9
+ };
10
+
11
+ export const accum_product = (arr) => {
12
+ let result = [];
13
+ let prod = 1;
14
+ for (let x of arr) {
15
+ prod *= x;
16
+ result.push(prod);
17
+ }
18
+ return result;
19
+ };
20
+
21
+ export const accum_max = (arr) => {
22
+ let result = [];
23
+ let m = -Infinity;
24
+ for (let x of arr) {
25
+ m = Math.max(m, x);
26
+ result.push(m);
27
+ }
28
+ return result;
29
+ };
30
+
31
+ export const accum_min = (arr) => {
32
+ let result = [];
33
+ let m = Infinity;
34
+ for (let x of arr) {
35
+ m = Math.min(m, x);
36
+ result.push(m);
37
+ }
38
+ return result;
39
+ };