ziko 0.54.0 → 0.54.2

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ziko",
3
- "version": "0.54.0",
3
+ "version": "0.54.2",
4
4
  "description": "A versatile JavaScript library offering a rich set of Hyperscript Based UI components, advanced mathematical utilities, interactivity ,animations, client side routing and more ...",
5
5
  "keywords": [
6
6
  "front-end",
@@ -1,4 +1,4 @@
1
- import { Matrix } from "../../math/matrix/matrix.js"
1
+ import { Matrix } from "../../math/matrix/index.js"
2
2
  const csv2arr = (csv, delimiter = ",")=>csv.trim().trimEnd().split("\n").map(n=>n.split(delimiter));
3
3
  const csv2matrix = (csv, delimiter = ",")=>new Matrix(csv2arr(csv,delimiter));
4
4
  const csv2object = (csv, delimiter = ",") => {
@@ -55,7 +55,16 @@ class Complex{
55
55
  : (str = `-${Math.abs(this.b)}*i`);
56
56
  return str;
57
57
  }
58
-
58
+ toFixed(n){
59
+ this.a = + this.a.toFixed(n);
60
+ this.b = + this.b.toFixed(n);
61
+ return this;
62
+ }
63
+ toPrecision(n){
64
+ this.a = + this.a.toPrecision(n);
65
+ this.b = + this.b.toPrecision(n);
66
+ return this;
67
+ }
59
68
  clone() {
60
69
  return new Complex(this.a, this.b);
61
70
  }
@@ -68,6 +77,13 @@ class Complex{
68
77
  static Zero() {
69
78
  return new Complex(0, 0);
70
79
  }
80
+ static Twidlle(N, K){
81
+ const phi = -2 * Math.PI * K / N;
82
+ return new Complex(
83
+ Math.cos(phi),
84
+ Math.sin(phi)
85
+ );
86
+ }
71
87
  get conj() {
72
88
  return new Complex(this.a, -this.b);
73
89
  }
@@ -98,22 +114,22 @@ class Complex{
98
114
  for (let i = 0; i < c.length; i++) {
99
115
  if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
100
116
  z *= c[i].z;
101
- phi += c[i].z;
117
+ phi += c[i].phi;
102
118
  }
103
- this.a = z*Math.cos(phi)
104
- this.b = z*Math.sin(phi)
105
- return this;
119
+ this.a = z * Math.cos(phi)
120
+ this.b = z * Math.sin(phi)
121
+ return this.toFixed(8);
106
122
  }
107
123
  div(...c){
108
124
  let {z, phi} = this;
109
125
  for (let i = 0; i < c.length; i++) {
110
126
  if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
111
127
  z /= c[i].z;
112
- phi -= c[i].z;
128
+ phi -= c[i].phi;
113
129
  }
114
- this.a = z*Math.cos(phi)
115
- this.b = z*Math.sin(phi)
116
- return this;
130
+ this.a = z * Math.cos(phi)
131
+ this.b = z * Math.sin(phi)
132
+ return this.toFixed(8);;
117
133
  }
118
134
  modulo(...c) {
119
135
  for (let i = 0; i < c.length; i++) {
@@ -123,6 +139,17 @@ class Complex{
123
139
  }
124
140
  return this;
125
141
  }
142
+ pow(...c){
143
+ let {z, phi} = this;
144
+ for (let i = 0; i < c.length; i++) {
145
+ if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
146
+ z *= Math.exp(c[i].a * Math.log(z) - c[i].b * phi);
147
+ phi += c[i].b * Math.log(z) + c[i].a * phi;
148
+ }
149
+ this.a = z * Math.cos(phi)
150
+ this.b = z * Math.sin(phi)
151
+ return this;
152
+ }
126
153
  static fromExpo(z, phi) {
127
154
  return new Complex(
128
155
  +(z * cos(phi)).toFixed(13),
@@ -1,5 +1,5 @@
1
1
  import { Complex } from "../../complex/index.js";
2
- import { Matrix } from "../../matrix/matrix.js";
2
+ import { Matrix } from "../../matrix/index.js";
3
3
  const Base={
4
4
  _mode:Number,
5
5
  _map:function(func,number,toBase){
@@ -1,5 +1,5 @@
1
1
  import { Complex } from "../../complex/index.js";
2
- import { Matrix } from "../../matrix/matrix.js";
2
+ import { Matrix } from "../../matrix/index.js";
3
3
  const Logic={
4
4
  _mode:Number,
5
5
  _map:function(func,a,b){
@@ -6,7 +6,7 @@ const _add = (x, y) =>{
6
6
  }
7
7
  }
8
8
  if(x.isComplex?.()){
9
- if(typeof y === 'number' || y.isComplex?.()) return new x.clone().add(y);
9
+ if(typeof y === 'number' || y.isComplex?.()) return x.clone().add(y);
10
10
  }
11
11
  }
12
12
 
@@ -16,7 +16,7 @@ const _sub = (x, y) =>{
16
16
  if(y.isComplex?.()) return new y.constructor(x - y.a, y.b);
17
17
  }
18
18
  if(x.isComplex?.()){
19
- if(typeof y === 'number' || y.isComplex?.()) return new x.clone().sub(y);
19
+ if(typeof y === 'number' || y.isComplex?.()) return x.clone().sub(y);
20
20
  }
21
21
  }
22
22
 
@@ -26,7 +26,7 @@ const _mul = (x, y) =>{
26
26
  if(y.isComplex?.()) return y.clone().mul(x);
27
27
  }
28
28
  if(x.isComplex?.()){
29
- if(typeof y === 'number' || y.isComplex?.()) return new x.clone().mul(y);
29
+ if(typeof y === 'number' || y.isComplex?.()) return x.clone().mul(y);
30
30
  }
31
31
  }
32
32
 
@@ -36,7 +36,7 @@ const _div = (x, y) =>{
36
36
  if(y.isComplex?.()) return new y.constructor(x, 0).div(y)
37
37
  }
38
38
  if(x.isComplex?.()){
39
- if(typeof y === 'number' || y.isComplex?.()) return new x.clone().mul(y);
39
+ if(typeof y === 'number' || y.isComplex?.()) return x.clone().mul(y);
40
40
  }
41
41
  }
42
42
 
@@ -46,7 +46,7 @@ const _modulo = (x, y) =>{
46
46
  if(y.isComplex?.()) return new y.constructor(x, 0).modulo(y)
47
47
  }
48
48
  if(x.isComplex?.()){
49
- if(typeof y === 'number' || y.isComplex?.()) return new x.clone().modulo(y);
49
+ if(typeof y === 'number' || y.isComplex?.()) return x.clone().modulo(y);
50
50
  }
51
51
  }
52
52
 
@@ -2,6 +2,7 @@ export * from './mapfun/index.js'
2
2
  export * from './nested/index.js'
3
3
  export * from './arithmetic/index.js'
4
4
  export * from './utils/index.js'
5
+ export * from './stats/index.js'
5
6
  // export const atan2=(x,y,rad=true)=>{
6
7
  // if(typeof x === "number"){
7
8
  // if(typeof y === "number")return rad?Math.atan2(x,y):Math.atan2(x,y)*180/Math.PI;
@@ -17,3 +17,17 @@ export const mapfun=(fun,...X)=>{
17
17
  });
18
18
  return Y.length==1? Y[0]: Y;
19
19
  }
20
+
21
+ export const apply_fun = (x, fn) => {
22
+ if (x.isComplex?.()) return new x.constructor(
23
+ fn(x.a),
24
+ fn(x.b)
25
+ )
26
+ if (x.isMatrix?.()) return new x.constructor(
27
+ x.rows,
28
+ x.cols,
29
+ x.arr.flat(1).map(fn)
30
+ )
31
+ if (x instanceof Array) mapfun(fn, ...x)
32
+ return fn(x)
33
+ }
@@ -1,8 +1,7 @@
1
1
  import { mapfun } from '../mapfun/index.js';
2
2
  import { complex } from '../../complex/index.js'
3
3
 
4
- export const deg2rad = (...deg) => mapfun(x => x * Math.PI / 180, ...deg);
5
- export const rad2deg = (...rad) => mapfun(x => x / Math.PI * 180, ...rad);
4
+ const PRECESION = 8
6
5
 
7
6
  export const abs = (...x) => mapfun(
8
7
  x =>{
@@ -37,8 +36,8 @@ export const sqrt = (...x) => mapfun(
37
36
  x=>{
38
37
  if(x.isComplex?.())
39
38
  return new x.constructor({z: x.z**(1/2), phi: x.phi/2});
40
- if(x < 0) return complex(0, Math.sqrt(-x))
41
- return Math.sqrt(x);
39
+ if(x < 0) return complex(0, Math.sqrt(-x)).toFixed(PRECESION)
40
+ return + Math.sqrt(x).toFixed(PRECESION);
42
41
  },
43
42
  ...x
44
43
  );
@@ -46,8 +45,8 @@ export const sqrt = (...x) => mapfun(
46
45
  export const cbrt = (...x) => mapfun(
47
46
  x=>{
48
47
  if(x.isComplex?.())
49
- return new x.constructor({z: x.z**(1/3), phi: x.phi/3})
50
- return Math.cbrt(x);
48
+ return new x.constructor({z: x.z**(1/3), phi: x.phi/3}).toFixed(PRECESION)
49
+ return + Math.cbrt(x).toFixed(PRECESION);
51
50
  },
52
51
  ...x
53
52
  );
@@ -58,8 +57,10 @@ export const nthr = (...x) => {
58
57
  return mapfun(
59
58
  x => {
60
59
  if(x.isComplex?.()) return new x.constructor({z: x.z ** (1/n), phi: x.phi / n});
61
- if(x<0) return n%2===2 ? complex(0, (-x)**(1/n)) : -1 * (-x)**(1/n)
62
- return x**(1/n)
60
+ if(x<0) return n %2 ===2
61
+ ? complex(0, (-x)**(1/n)).toFixed(PRECESION)
62
+ : + (-1 * (-x)**(1/n)).toFixed(PRECESION)
63
+ return + (x**(1/n)).toFixed(PRECESION)
63
64
  },
64
65
  ...x
65
66
  )
@@ -79,7 +80,7 @@ export const croot = (...x) =>{
79
80
  return new c.constructor(
80
81
  A * Math.cos(B),
81
82
  A * Math.sin(B)
82
- )
83
+ ).toFixed(PRECESION)
83
84
  },
84
85
  ...x
85
86
  )
@@ -90,8 +91,8 @@ export const exp = (...x) => mapfun(
90
91
  if(x.isComplex?.()) return new x.constructor(
91
92
  Math.exp(x.a) * Math.cos(x.b),
92
93
  Math.exp(x.a) * Math.sin(x.b)
93
- );
94
- return Math.exp(x)
94
+ ).toFixed(PRECESION);
95
+ return + Math.exp(x).toFixed(PRECESION)
95
96
  }
96
97
  ,...x
97
98
  );
@@ -101,8 +102,8 @@ export const ln = (...x) => mapfun(
101
102
  if(x.isComplex?.()) return new x.constructor(
102
103
  Math.log(x.z),
103
104
  x.phi
104
- );
105
- return Math.log(x)
105
+ ).toFixed(PRECESION);
106
+ return + Math.log(x).toFixed(PRECESION)
106
107
  }
107
108
  ,...x
108
109
  );
@@ -177,8 +178,8 @@ export const cos = (...x) => mapfun(
177
178
  if(x.isComplex?.()) return new x.constructor(
178
179
  Math.cos(x.a) * Math.cosh(x.b),
179
180
  -Math.sin(x.a) * Math.sinh(x.b)
180
- );
181
- return Math.cos(x)
181
+ ).toFixed(PRECESION);
182
+ return + Math.cos(x).toFixed(PRECESION)
182
183
  }
183
184
  ,...x
184
185
  );
@@ -188,8 +189,8 @@ export const sin = (...x) => mapfun(
188
189
  if(x?.isComplex) return new x.constructor(
189
190
  Math.sin(x.a) * Math.cosh(x.b),
190
191
  Math.cos(x.a) * Math.sinh(x.b)
191
- );
192
- return Math.sin(x)
192
+ ).toFixed(PRECESION);
193
+ return + Math.sin(x).toFixed(PRECESION)
193
194
  }
194
195
  , ...x
195
196
  );
@@ -201,9 +202,9 @@ export const tan = (...x) => mapfun(
201
202
  return new x.constructor(
202
203
  Math.sin(2*x.a) / D,
203
204
  Math.sinh(2*x.b) / D
204
- );
205
+ ).toFixed(PRECESION);
205
206
  }
206
- return Math.tan(x)
207
+ return + Math.tan(x).toFixed(PRECESION)
207
208
  },
208
209
  ...x
209
210
  );
@@ -213,7 +214,7 @@ export const sec = (...x) => mapfun(
213
214
  if(x.isComplex?.()) {
214
215
 
215
216
  }
216
- return 1 / Math.cos(x)
217
+ return + (1 / Math.cos(x)).toFixed(PRECESION)
217
218
  }
218
219
  ,...x
219
220
  );
@@ -229,9 +230,9 @@ export const acos = (...x) => mapfun(
229
230
  return new x.constructor(
230
231
  Math.acos((Rp - Rm) / 2),
231
232
  -Math.acosh((Rp + Rm) / 2),
232
- )
233
+ ).toFixed(PRECESION)
233
234
  }
234
- return Math.acos(x)
235
+ return + Math.acos(x).toFixed(PRECESION)
235
236
  },
236
237
  ...x
237
238
  );
@@ -245,9 +246,9 @@ export const asin = (...x) => mapfun(
245
246
  return new x.constructor(
246
247
  Math.asin((Rp - Rm) / 2),
247
248
  Math.acosh((Rp + Rm) / 2)
248
- );
249
+ ).toFixed(PRECESION);
249
250
  }
250
- return Math.asin(x);
251
+ return + Math.asin(x).toFixed(PRECESION);
251
252
  },
252
253
  ...x
253
254
  );
@@ -259,9 +260,9 @@ export const atan = (...x) => mapfun(
259
260
  return new x.constructor(
260
261
  Math.atan((a*2/(1-a**2-b**2)))/2,
261
262
  Math.log((a**2 + (1+b)**2)/(a**2 + (1-b)**2))/4
262
- )
263
+ ).toFixed(PRECESION)
263
264
  }
264
- return Math.atan(x);
265
+ return + Math.atan(x).toFixed(PRECESION);
265
266
  },
266
267
  ...x
267
268
  );
@@ -273,9 +274,9 @@ export const acot = (...x) => mapfun(
273
274
  return new x.constructor(
274
275
  Math.atan(2*a/(a**2+(b-1)*(b+1)))/2,
275
276
  Math.log((a**2 + (b-1)**2)/(a**2 + (b+1)**2))/4
276
- )
277
+ ).toFixed(PRECESION)
277
278
  }
278
- return Math.PI/2 - Math.atan(x);
279
+ return + (Math.PI/2 - Math.atan(x)).toFixed(PRECESION);
279
280
  },
280
281
  ...x
281
282
  );
@@ -286,8 +287,8 @@ export const cosh = (...x) => mapfun(
286
287
  if(x?.isComplex) return new x.constructor(
287
288
  Math.cosh(x.a) * Math.cos(x.b),
288
289
  Math.sinh(x.a) * Math.sin(x.b)
289
- );
290
- return Math.cosh(x)
290
+ ).toFixed(PRECESION);
291
+ return + Math.cosh(x).toFixed(PRECESION)
291
292
  },
292
293
  ...x
293
294
  )
@@ -296,8 +297,8 @@ export const sinh = (...x) => mapfun(
296
297
  if(x?.isComplex) return new x.constructor(
297
298
  Math.sinh(x.a) * Math.cos(x.b),
298
299
  Math.cosh(x.a) * Math.sin(x.b)
299
- );
300
- return Math.sinh(x)
300
+ ).toFixed(PRECESION);
301
+ return + Math.sinh(x).toFixed(PRECESION)
301
302
  },
302
303
  ...x
303
304
  )
@@ -308,9 +309,9 @@ export const tanh = (...x) => mapfun(
308
309
  return new x.constructor(
309
310
  Math.sinh(2*a) / D,
310
311
  Math.sin(2*b) / D
311
- )
312
+ ).toFixed(PRECESION)
312
313
  }
313
- return Math.tanh(x)
314
+ return + Math.tanh(x).toFixed(PRECESION)
314
315
  },
315
316
  ...x
316
317
  )
@@ -323,9 +324,9 @@ export const coth = (...x) => mapfun(
323
324
  return new x.constructor(
324
325
  Math.cosh(a) * Math.sinh(a) / D,
325
326
  - Math.sin(b) * Math.cos(b) / D
326
- )
327
+ ).toFixed(PRECESION)
327
328
  }
328
- return 1/Math.tanh(x)
329
+ return + (1 / Math.tanh(x)).toFixed(PRECESION)
329
330
  },
330
331
  ...x
331
332
  )
@@ -335,7 +336,7 @@ export const acosh = (...x) => mapfun(
335
336
  if(x?.isComplex){
336
337
  return ln(x.clone().add(sqrt(x.clone().mul(x.clone()).sub(1))))
337
338
  }
338
- return Math.acosh(x)
339
+ return + Math.acosh(x).toFixed(PRECESION)
339
340
  },
340
341
  ...x
341
342
  )
@@ -345,7 +346,7 @@ export const asinh = (...x) => mapfun(
345
346
  if(x?.isComplex){
346
347
  return ln(x.clone().add(sqrt(x.clone().mul(x.clone()).add(1))))
347
348
  }
348
- return Math.asinh(x)
349
+ return + Math.asinh(x).toFixed(PRECESION)
349
350
  },
350
351
  ...x
351
352
  )
@@ -355,7 +356,7 @@ export const atanh = (...x) => mapfun(
355
356
  if(x?.isComplex){
356
357
 
357
358
  }
358
- return Math.atanh(x)
359
+ return + Math.atanh(x).toFixed(PRECESION)
359
360
  },
360
361
  ...x
361
362
  )
@@ -365,7 +366,7 @@ export const sig = (...x) => mapfun(
365
366
  if(x?.isComplex){
366
367
 
367
368
  }
368
- return 1/(1+Math.exp(-x))
369
+ return + 1/(1 + Math.exp(-x)).toFixed(PRECESION)
369
370
  },
370
371
  ...x
371
372
  )
@@ -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);