ziko 0.54.4 → 0.55.0
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/dist/ziko.cjs +298 -444
- package/dist/ziko.js +347 -661
- package/dist/ziko.min.js +2 -2
- package/dist/ziko.mjs +341 -652
- package/package.json +1 -1
- package/src/math/--discret/index.js +12 -0
- package/src/math/complex/index.js +18 -12
- package/src/math/functions/conversions/index.js +61 -0
- package/src/math/functions/index.js +2 -1
- package/src/math/functions/logic/index.js +54 -0
- package/src/math/functions/signal/index.js +1 -1
- package/src/math/functions/stats/index.js +14 -2
- package/src/math/functions/utils/index.js +0 -58
- package/src/math/index.js +2 -2
- package/src/math/matrix/index.js +52 -35
- package/src/math/random/index.js +111 -155
- package/src/math/utils/conversions.js +17 -17
- package/src/math/utils/index.js +10 -10
- package/types/math/complex/index.d.ts +5 -5
- package/types/math/functions/logic/index.d.ts +11 -0
- package/src/math/discret/Combinaison/index.js +0 -34
- package/src/math/discret/Conversion/index.js +0 -86
- package/src/math/discret/Logic/index.js +0 -46
- package/src/math/discret/Permutation/index.js +0 -31
- package/src/math/discret/index.js +0 -12
- package/src/math/statistics/functions/index.js +0 -100
- package/src/math/statistics/index.js +0 -16
- /package/src/math/{discret → --discret}/Set/index.js +0 -0
- /package/src/math/{discret → --discret}/Set/power-set.js +0 -0
- /package/src/math/{discret → --discret}/Set/sub-set.js +0 -0
- /package/src/math/functions/{nested → ufunc}/index.js +0 -0
package/dist/ziko.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/*
|
|
3
3
|
Project: ziko.js
|
|
4
4
|
Author: Zakaria Elalaoui
|
|
5
|
-
Date :
|
|
5
|
+
Date : Sat Dec 13 2025 01:41:10 GMT+0100 (UTC+01:00)
|
|
6
6
|
Git-Repo : https://github.com/zakarialaoui10/ziko.js
|
|
7
7
|
Git-Wiki : https://github.com/zakarialaoui10/ziko.js/wiki
|
|
8
8
|
Released under MIT License
|
|
@@ -46,8 +46,280 @@ const apply_fun = (x, fn) => {
|
|
|
46
46
|
return fn(x)
|
|
47
47
|
};
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
const base2base = (value, fromBase, toBase) => {
|
|
50
|
+
|
|
51
|
+
const dec = parseInt(value, fromBase);
|
|
52
|
+
if (Number.isNaN(dec)) throw new TypeError('Invalid value for the given base');
|
|
53
|
+
|
|
54
|
+
return dec.toString(toBase);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const _add = (x, y) =>{
|
|
58
|
+
if(typeof x === 'number'){
|
|
59
|
+
if(typeof y === 'number') return x + y;
|
|
60
|
+
if(y.isComplex?.()) {
|
|
61
|
+
return y.clone().add(x);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if(x.isComplex?.()){
|
|
65
|
+
if(typeof y === 'number' || y.isComplex?.()) return x.clone().add(y);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const _sub = (x, y) =>{
|
|
70
|
+
if(typeof x === 'number'){
|
|
71
|
+
if(typeof y === 'number') return x - y;
|
|
72
|
+
if(y.isComplex?.()) return new y.constructor(x - y.a, y.b);
|
|
73
|
+
}
|
|
74
|
+
if(x.isComplex?.()){
|
|
75
|
+
if(typeof y === 'number' || y.isComplex?.()) return x.clone().sub(y);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const _mul = (x, y) =>{
|
|
80
|
+
if(typeof x === 'number'){
|
|
81
|
+
if(typeof y === 'number') return x * y;
|
|
82
|
+
if(y.isComplex?.()) return y.clone().mul(x);
|
|
83
|
+
}
|
|
84
|
+
if(x.isComplex?.()){
|
|
85
|
+
if(typeof y === 'number' || y.isComplex?.()) return x.clone().mul(y);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const _div = (x, y) =>{
|
|
90
|
+
if(typeof x === 'number'){
|
|
91
|
+
if(typeof y === 'number') return x / y;
|
|
92
|
+
if(y.isComplex?.()) return new y.constructor(x, 0).div(y)
|
|
93
|
+
}
|
|
94
|
+
if(x.isComplex?.()){
|
|
95
|
+
if(typeof y === 'number' || y.isComplex?.()) return x.clone().mul(y);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const _modulo = (x, y) =>{
|
|
100
|
+
if(typeof x === 'number'){
|
|
101
|
+
if(typeof y === 'number') return x % y;
|
|
102
|
+
if(y.isComplex?.()) return new y.constructor(x, 0).modulo(y)
|
|
103
|
+
}
|
|
104
|
+
if(x.isComplex?.()){
|
|
105
|
+
if(typeof y === 'number' || y.isComplex?.()) return x.clone().modulo(y);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const add=(a,...b)=>{
|
|
110
|
+
let res = a;
|
|
111
|
+
for(let i=0; i<b.length; i++)
|
|
112
|
+
res = _add(res, b[i]);
|
|
113
|
+
return res;
|
|
114
|
+
};
|
|
115
|
+
const sub=(a,...b)=>{
|
|
116
|
+
let res = a;
|
|
117
|
+
for(let i=0; i<b.length; i++)
|
|
118
|
+
res = _sub(res, b[i]);
|
|
119
|
+
return res;
|
|
120
|
+
};
|
|
121
|
+
const mul=(a,...b)=>{
|
|
122
|
+
let res = a;
|
|
123
|
+
for(let i=0; i<b.length; i++)
|
|
124
|
+
res = _mul(res, b[i]);
|
|
125
|
+
return res;
|
|
126
|
+
};
|
|
127
|
+
const div=(a,...b)=>{
|
|
128
|
+
let res = a;
|
|
129
|
+
for(let i=0; i<b.length; i++)
|
|
130
|
+
res = _div(res, b[i]);
|
|
131
|
+
return res;
|
|
132
|
+
};
|
|
133
|
+
const modulo=(a,...b)=>{
|
|
134
|
+
let res = a;
|
|
135
|
+
for(let i=0; i<b.length; i++)
|
|
136
|
+
res = _modulo(res, b[i]);
|
|
137
|
+
return res;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const min$1 = (...x) => Math.min(...x);
|
|
141
|
+
const max$1 = (...x) => Math.max(...x);
|
|
142
|
+
|
|
143
|
+
const binomial = (n, k) =>{
|
|
144
|
+
if(n !== Math.floor(n)) return TypeError('n must be an integer');
|
|
145
|
+
if(k !== Math.floor(k)) return TypeError('k must be an integer');
|
|
146
|
+
if (n < 0) return TypeError('n must be non-negative');
|
|
147
|
+
if (k < 0 || n < 0 || k > n) return 0;
|
|
148
|
+
if (k > n - k) k = n - k;
|
|
149
|
+
let c = 1, i;
|
|
150
|
+
for (i = 0; i < k; i++)
|
|
151
|
+
c = c * (n - i) / (i + 1);
|
|
152
|
+
return c;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
const mean = (...x) => x.reduce((a, b) => a + b) / x.length;
|
|
156
|
+
|
|
157
|
+
const variance = (...x) => {
|
|
158
|
+
const n = x.length;
|
|
159
|
+
if (n === 0) return NaN;
|
|
160
|
+
const x_mean = mean(...x);
|
|
161
|
+
return x.reduce((sum, xi) => sum + (xi - x_mean) ** 2, 0) / n;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
const std = (...x) => Math.sqrt(variance(...x));
|
|
165
|
+
|
|
166
|
+
const accum_sum = (...x) => {
|
|
167
|
+
let result = [];
|
|
168
|
+
let total = 0, i, n = x.length;
|
|
169
|
+
for(i = 0; i < n ; i++){
|
|
170
|
+
total = add(total, x[i]);
|
|
171
|
+
result.push(total);
|
|
172
|
+
}
|
|
173
|
+
return result;
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
const accum_prod = (...x) => {
|
|
177
|
+
let result = [];
|
|
178
|
+
let prod = 1, i, n = x.length;
|
|
179
|
+
for(i = 0; i < n ; i++){
|
|
180
|
+
prod = mul(prod, x[i]);
|
|
181
|
+
result.push(prod);
|
|
182
|
+
}
|
|
183
|
+
return result;
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
const percentile = (X, p) => {
|
|
187
|
+
if (X.length === 0)
|
|
188
|
+
return NaN;
|
|
189
|
+
let a = [...X].sort((x, y) => x - y);
|
|
190
|
+
let index = (p / 100) * (a.length - 1);
|
|
191
|
+
let i = Math.floor(index);
|
|
192
|
+
let f = index - i;
|
|
193
|
+
if (i === a.length - 1)
|
|
194
|
+
return a[i];
|
|
195
|
+
return a[i] * (1 - f) + a[i + 1] * f;
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
const median = X => percentile(X, 50);
|
|
199
|
+
|
|
200
|
+
class Random {
|
|
201
|
+
static int(a, b){
|
|
202
|
+
return Math.floor(this.float(a, b));
|
|
203
|
+
}
|
|
204
|
+
static float(a, b){
|
|
205
|
+
return b !== undefined
|
|
206
|
+
? Math.random() * (b - a) + a
|
|
207
|
+
: Math.random() * a;
|
|
208
|
+
}
|
|
209
|
+
static bin(){
|
|
210
|
+
return this.int(2);
|
|
211
|
+
}
|
|
212
|
+
static oct(){
|
|
213
|
+
return this.int(8);
|
|
214
|
+
}
|
|
215
|
+
static dec(){
|
|
216
|
+
return this.int(10);
|
|
217
|
+
}
|
|
218
|
+
static hex(){
|
|
219
|
+
return base2base(this.int(16), 10, 16);
|
|
220
|
+
}
|
|
221
|
+
static char(upperCase = false){
|
|
222
|
+
const i = upperCase
|
|
223
|
+
? this.int(65, 91)
|
|
224
|
+
: this.int(97, 123);
|
|
225
|
+
return String.fromCharCode(i);
|
|
226
|
+
}
|
|
227
|
+
static bool(){
|
|
228
|
+
return Boolean(this.int(2));
|
|
229
|
+
}
|
|
230
|
+
static get color(){
|
|
231
|
+
return {
|
|
232
|
+
hex : () =>
|
|
233
|
+
`#${this.int(0xffffff).toString(16).padStart(6, '0')}`,
|
|
234
|
+
|
|
235
|
+
hexa : () => {
|
|
236
|
+
const [r,g,b,a] = Array.from(
|
|
237
|
+
{length:4},
|
|
238
|
+
() => this.int(0xff).toString(16).padStart(2,'0')
|
|
239
|
+
);
|
|
240
|
+
return `#${r}${g}${b}${a}`;
|
|
241
|
+
},
|
|
242
|
+
rgb : () => {
|
|
243
|
+
const [r,g,b] = Array.from({length:3}, () => this.int(0xff));
|
|
244
|
+
return `rgb(${r}, ${g}, ${b})`;
|
|
245
|
+
},
|
|
246
|
+
rgba : () => {
|
|
247
|
+
const [r,g,b] = Array.from({length:3}, () => this.int(0xff));
|
|
248
|
+
const a = Math.random().toFixed(2);
|
|
249
|
+
return `rgba(${r}, ${g}, ${b}, ${a})`;
|
|
250
|
+
},
|
|
251
|
+
hsl : () => {
|
|
252
|
+
const h = this.int(360);
|
|
253
|
+
const s = this.int(100);
|
|
254
|
+
const l = this.int(100);
|
|
255
|
+
return `hsl(${h}, ${s}%, ${l}%)`;
|
|
256
|
+
},
|
|
257
|
+
hsla : () => {
|
|
258
|
+
const h = this.int(360);
|
|
259
|
+
const s = this.int(100);
|
|
260
|
+
const l = this.int(100);
|
|
261
|
+
const a = Math.random().toFixed(2);
|
|
262
|
+
return `hsla(${h}, ${s}%, ${l}%, ${a})`;
|
|
263
|
+
},
|
|
264
|
+
gray : () => {
|
|
265
|
+
const g = this.int(0xff);
|
|
266
|
+
return `rgb(${g}, ${g}, ${g})`;
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
static get sample(){
|
|
271
|
+
const R = this;
|
|
272
|
+
return {
|
|
273
|
+
int : (n,a,b) => Array.from({length:n}, () => R.int(a,b)),
|
|
274
|
+
float : (n,a,b) => Array.from({length:n}, () => R.float(a,b)),
|
|
275
|
+
char : (n,upper=false) => Array.from({length:n}, () => R.char(upper)),
|
|
276
|
+
bool : n => Array.from({length:n}, () => R.bool()),
|
|
277
|
+
bin : n => Array.from({length:n}, () => R.bin()),
|
|
278
|
+
oct : n => Array.from({length:n}, () => R.oct()),
|
|
279
|
+
dec : n => Array.from({length:n}, () => R.dec()),
|
|
280
|
+
hex : n => Array.from({length:n}, () => R.hex()),
|
|
281
|
+
get color(){
|
|
282
|
+
return {
|
|
283
|
+
hex : n => Array.from({length:n}, () => R.color.hex()),
|
|
284
|
+
hexa : n => Array.from({length:n}, () => R.color.hexa()),
|
|
285
|
+
rgb : n => Array.from({length:n}, () => R.color.rgb()),
|
|
286
|
+
rgba : n => Array.from({length:n}, () => R.color.rgba()),
|
|
287
|
+
hsl : n => Array.from({length:n}, () => R.color.hsl()),
|
|
288
|
+
hsla : n => Array.from({length:n}, () => R.color.hsla()),
|
|
289
|
+
gray : n => Array.from({length:n}, () => R.color.gray())
|
|
290
|
+
};
|
|
291
|
+
},
|
|
292
|
+
choice : (n, choices, p) =>
|
|
293
|
+
Array.from({length:n}, () => R.choice(choices, p))
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
static shuffle(arr){
|
|
297
|
+
return [...arr].sort(() => 0.5 - Math.random());
|
|
298
|
+
}
|
|
299
|
+
static choice(choices = [1,2,3], p = new Array(choices.length).fill(1 / choices.length)){
|
|
300
|
+
const acc = accum_sum(...p).map(v => v * 100);
|
|
301
|
+
const pool = new Array(100);
|
|
302
|
+
pool.fill(choices[0], 0, acc[0]);
|
|
303
|
+
for(let i=1;i<choices.length;i++)
|
|
304
|
+
pool.fill(choices[i], acc[i-1], acc[i]);
|
|
305
|
+
return pool[this.int(pool.length)];
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
globalThis.Random = Random;
|
|
311
|
+
|
|
312
|
+
// // (upperCase) => upperCase ? : String.fromCharCode(rand_int(97,120))
|
|
313
|
+
// class Random {
|
|
314
|
+
// static string(length,upperCase){
|
|
315
|
+
// return length instanceof Array?
|
|
316
|
+
// new Array(this.int(...length)).fill(0).map(() => this.char(upperCase)).join(""):
|
|
317
|
+
// new Array(length).fill(0).map(() => this.char(upperCase)).join("");
|
|
318
|
+
// }
|
|
319
|
+
|
|
320
|
+
// }
|
|
321
|
+
// export{Random}
|
|
322
|
+
|
|
51
323
|
class Complex{
|
|
52
324
|
constructor(a = 0, b = 0) {
|
|
53
325
|
if(a instanceof Complex){
|
|
@@ -125,7 +397,13 @@ class Complex{
|
|
|
125
397
|
static Zero() {
|
|
126
398
|
return new Complex(0, 0);
|
|
127
399
|
}
|
|
128
|
-
static
|
|
400
|
+
static get Random(){
|
|
401
|
+
return {
|
|
402
|
+
int : (a, b)=> new Complex(...Random.sample.int(2, a, b) ),
|
|
403
|
+
float : (a, b)=> new Complex(...Random.sample.float(2, a, b) ),
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
static Twiddle(N, K){
|
|
129
407
|
const phi = -2 * Math.PI * K / N;
|
|
130
408
|
return new Complex(
|
|
131
409
|
Math.cos(phi),
|
|
@@ -625,89 +903,6 @@ const sig = (...x) => mapfun(
|
|
|
625
903
|
...x
|
|
626
904
|
);
|
|
627
905
|
|
|
628
|
-
const _add = (x, y) =>{
|
|
629
|
-
if(typeof x === 'number'){
|
|
630
|
-
if(typeof y === 'number') return x + y;
|
|
631
|
-
if(y.isComplex?.()) {
|
|
632
|
-
return y.clone().add(x);
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
if(x.isComplex?.()){
|
|
636
|
-
if(typeof y === 'number' || y.isComplex?.()) return x.clone().add(y);
|
|
637
|
-
}
|
|
638
|
-
};
|
|
639
|
-
|
|
640
|
-
const _sub = (x, y) =>{
|
|
641
|
-
if(typeof x === 'number'){
|
|
642
|
-
if(typeof y === 'number') return x - y;
|
|
643
|
-
if(y.isComplex?.()) return new y.constructor(x - y.a, y.b);
|
|
644
|
-
}
|
|
645
|
-
if(x.isComplex?.()){
|
|
646
|
-
if(typeof y === 'number' || y.isComplex?.()) return x.clone().sub(y);
|
|
647
|
-
}
|
|
648
|
-
};
|
|
649
|
-
|
|
650
|
-
const _mul = (x, y) =>{
|
|
651
|
-
if(typeof x === 'number'){
|
|
652
|
-
if(typeof y === 'number') return x * y;
|
|
653
|
-
if(y.isComplex?.()) return y.clone().mul(x);
|
|
654
|
-
}
|
|
655
|
-
if(x.isComplex?.()){
|
|
656
|
-
if(typeof y === 'number' || y.isComplex?.()) return x.clone().mul(y);
|
|
657
|
-
}
|
|
658
|
-
};
|
|
659
|
-
|
|
660
|
-
const _div = (x, y) =>{
|
|
661
|
-
if(typeof x === 'number'){
|
|
662
|
-
if(typeof y === 'number') return x / y;
|
|
663
|
-
if(y.isComplex?.()) return new y.constructor(x, 0).div(y)
|
|
664
|
-
}
|
|
665
|
-
if(x.isComplex?.()){
|
|
666
|
-
if(typeof y === 'number' || y.isComplex?.()) return x.clone().mul(y);
|
|
667
|
-
}
|
|
668
|
-
};
|
|
669
|
-
|
|
670
|
-
const _modulo = (x, y) =>{
|
|
671
|
-
if(typeof x === 'number'){
|
|
672
|
-
if(typeof y === 'number') return x % y;
|
|
673
|
-
if(y.isComplex?.()) return new y.constructor(x, 0).modulo(y)
|
|
674
|
-
}
|
|
675
|
-
if(x.isComplex?.()){
|
|
676
|
-
if(typeof y === 'number' || y.isComplex?.()) return x.clone().modulo(y);
|
|
677
|
-
}
|
|
678
|
-
};
|
|
679
|
-
|
|
680
|
-
const add=(a,...b)=>{
|
|
681
|
-
let res = a;
|
|
682
|
-
for(let i=0; i<b.length; i++)
|
|
683
|
-
res = _add(res, b[i]);
|
|
684
|
-
return res;
|
|
685
|
-
};
|
|
686
|
-
const sub=(a,...b)=>{
|
|
687
|
-
let res = a;
|
|
688
|
-
for(let i=0; i<b.length; i++)
|
|
689
|
-
res = _sub(res, b[i]);
|
|
690
|
-
return res;
|
|
691
|
-
};
|
|
692
|
-
const mul=(a,...b)=>{
|
|
693
|
-
let res = a;
|
|
694
|
-
for(let i=0; i<b.length; i++)
|
|
695
|
-
res = _mul(res, b[i]);
|
|
696
|
-
return res;
|
|
697
|
-
};
|
|
698
|
-
const div=(a,...b)=>{
|
|
699
|
-
let res = a;
|
|
700
|
-
for(let i=0; i<b.length; i++)
|
|
701
|
-
res = _div(res, b[i]);
|
|
702
|
-
return res;
|
|
703
|
-
};
|
|
704
|
-
const modulo=(a,...b)=>{
|
|
705
|
-
let res = a;
|
|
706
|
-
for(let i=0; i<b.length; i++)
|
|
707
|
-
res = _modulo(res, b[i]);
|
|
708
|
-
return res;
|
|
709
|
-
};
|
|
710
|
-
|
|
711
906
|
const deg2rad = (...deg) => mapfun(x => x * Math.PI / 180, ...deg);
|
|
712
907
|
const rad2deg = (...rad) => mapfun(x => x / Math.PI * 180, ...rad);
|
|
713
908
|
|
|
@@ -728,64 +923,6 @@ const map$1 = (x, a, b, c, d) => apply_fun(
|
|
|
728
923
|
v => lerp(norm(v, a, b), c, d)
|
|
729
924
|
);
|
|
730
925
|
|
|
731
|
-
|
|
732
|
-
// export const norm = (x, min, max) => {
|
|
733
|
-
// if(x.isComplex?.()) return new x.constructor(
|
|
734
|
-
// norm(x.a, min, max),
|
|
735
|
-
// norm(x.b, min, max)
|
|
736
|
-
// )
|
|
737
|
-
// if(x.isMatrix?.()) return new x.constructor(
|
|
738
|
-
// x.rows,
|
|
739
|
-
// x.cols,
|
|
740
|
-
// norm(x.arr.flat(1), min, max)
|
|
741
|
-
// );
|
|
742
|
-
// if(x instanceof Array) return mapfun(n => norm(n, min, max), ...x);
|
|
743
|
-
// return min !== max ? (x - min) / (max - min) : 0;
|
|
744
|
-
// }
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
// export const lerp = (x, min, max) => {
|
|
748
|
-
// if(x.isComplex?.()) return new x.constructor(
|
|
749
|
-
// lerp(x.a, min, max),
|
|
750
|
-
// lerp(x.b, min, max)
|
|
751
|
-
// )
|
|
752
|
-
// if(x.isMatrix?.()) return new x.constructor(
|
|
753
|
-
// x.rows,
|
|
754
|
-
// x.cols,
|
|
755
|
-
// lerp(x.arr.flat(1), min, max)
|
|
756
|
-
// );
|
|
757
|
-
// if(x instanceof Array) return mapfun(n => lerp(n, min, max), ...x);
|
|
758
|
-
// return (max - min) * x + min;
|
|
759
|
-
// }
|
|
760
|
-
|
|
761
|
-
// export const map = (x, a, b, c, d) => {
|
|
762
|
-
// if(x.isComplex?.()) return new x.constructor(
|
|
763
|
-
// map(x.a, a, b, c, d),
|
|
764
|
-
// map(x.b, a, b, c, d)
|
|
765
|
-
// )
|
|
766
|
-
// if(x.isMatrix?.()) return new x.constructor(
|
|
767
|
-
// x.rows,
|
|
768
|
-
// x.cols,
|
|
769
|
-
// map(x.arr.flat(1), a, b, c, d)
|
|
770
|
-
// );
|
|
771
|
-
// if(x instanceof Array) return mapfun(n => map(n, a, b, c, d), ...x);
|
|
772
|
-
// return lerp(norm(x, a, b), c, d);
|
|
773
|
-
// }
|
|
774
|
-
|
|
775
|
-
// export const clamp = (x, min, max) => {
|
|
776
|
-
// if(x.isComplex?.()) return new x.constructor(
|
|
777
|
-
// clamp(x.a, min, max),
|
|
778
|
-
// clamp(x.b, min, max)
|
|
779
|
-
// )
|
|
780
|
-
// if(x.isMatrix?.()) return new x.constructor(
|
|
781
|
-
// x.rows,
|
|
782
|
-
// x.cols,
|
|
783
|
-
// clamp(x.arr.flat(1), min, max)
|
|
784
|
-
// );
|
|
785
|
-
// if(x instanceof Array) return mapfun(n => clamp(n, min, max), ...x);
|
|
786
|
-
// return Math.min(Math.max(x, min), max)
|
|
787
|
-
// }
|
|
788
|
-
|
|
789
926
|
const hypot = (...x) => {
|
|
790
927
|
const c0 = x.find(a => a.isComplex?.());
|
|
791
928
|
if (c0) {
|
|
@@ -810,53 +947,59 @@ const atan2 = (y, x, rad = true) => {
|
|
|
810
947
|
return rad ? phi : phi * 180 / Math.PI;
|
|
811
948
|
};
|
|
812
949
|
|
|
813
|
-
const
|
|
814
|
-
|
|
950
|
+
const not = x => {
|
|
951
|
+
if(x.isComplex?.()) return new x.constructor(not(x.a), not(x.b))
|
|
952
|
+
if(x.isMatrix?.()) return new x.constructor(x.rows, x.cols, x.arr.flat(1).map(not))
|
|
953
|
+
return + !x;
|
|
954
|
+
};
|
|
955
|
+
const handle_complex_and_matrix = (x, operation) => {
|
|
956
|
+
if (x.every(n => n.isComplex?.())) {
|
|
957
|
+
const Re = x.map(n => n.a);
|
|
958
|
+
const Im = x.map(n => n.b);
|
|
959
|
+
return new x[0].constructor(
|
|
960
|
+
operation(...Re),
|
|
961
|
+
operation(...Im)
|
|
962
|
+
);
|
|
963
|
+
}
|
|
815
964
|
|
|
816
|
-
|
|
965
|
+
if (x.every(n => n.isMatrix?.())) {
|
|
966
|
+
if (!x.every(mat => mat.rows === x[0].rows && mat.cols === x[0].cols)) {
|
|
967
|
+
return TypeError('All matrices must have the same shape');
|
|
968
|
+
}
|
|
817
969
|
|
|
818
|
-
const
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
970
|
+
const { rows, cols } = x[0];
|
|
971
|
+
const Y = Array.from({ length: rows }, (_, i) =>
|
|
972
|
+
Array.from({ length: cols }, (_, j) =>
|
|
973
|
+
operation(...x.map(mat => mat.arr[i][j]))
|
|
974
|
+
)
|
|
975
|
+
);
|
|
976
|
+
return new x[0].constructor(Y);
|
|
977
|
+
}
|
|
824
978
|
|
|
825
|
-
|
|
979
|
+
return null; // Return null if no Complex or Matrix found
|
|
980
|
+
};
|
|
826
981
|
|
|
827
|
-
const
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
total = add(total, x[i]);
|
|
832
|
-
result.push(total);
|
|
833
|
-
}
|
|
834
|
-
return result;
|
|
982
|
+
const and = (...x) => {
|
|
983
|
+
const result = handle_complex_and_matrix(x, and);
|
|
984
|
+
if (result !== null) return result;
|
|
985
|
+
return x.reduce((n, m) => (n &= m), 1);
|
|
835
986
|
};
|
|
836
987
|
|
|
837
|
-
const
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
prod = mul(prod, x[i]);
|
|
842
|
-
result.push(prod);
|
|
843
|
-
}
|
|
844
|
-
return result;
|
|
988
|
+
const or = (...x) => {
|
|
989
|
+
const result = handle_complex_and_matrix(x, or);
|
|
990
|
+
if (result !== null) return result;
|
|
991
|
+
return x.reduce((n, m) => (n |= m), 0);
|
|
845
992
|
};
|
|
846
993
|
|
|
847
|
-
const
|
|
848
|
-
|
|
849
|
-
return
|
|
850
|
-
|
|
851
|
-
let index = (p / 100) * (a.length - 1);
|
|
852
|
-
let i = Math.floor(index);
|
|
853
|
-
let f = index - i;
|
|
854
|
-
if (i === a.length - 1)
|
|
855
|
-
return a[i];
|
|
856
|
-
return a[i] * (1 - f) + a[i + 1] * f;
|
|
994
|
+
const xor = (...x) => {
|
|
995
|
+
const result = handle_complex_and_matrix(x, xor);
|
|
996
|
+
if (result !== null) return result;
|
|
997
|
+
return x.reduce((n, m) => (n ^= m), 0);
|
|
857
998
|
};
|
|
858
999
|
|
|
859
|
-
const
|
|
1000
|
+
const nand = (...x) => not(and(...x));
|
|
1001
|
+
const nor = (...x) => not(or(...x));
|
|
1002
|
+
const xnor = (...x) => not(xor(...x));
|
|
860
1003
|
|
|
861
1004
|
const preload=(url)=>{
|
|
862
1005
|
const xhr = new XMLHttpRequest();
|
|
@@ -3460,6 +3603,7 @@ class Matrix{
|
|
|
3460
3603
|
get inv() {
|
|
3461
3604
|
return matrix_inverse(this)
|
|
3462
3605
|
}
|
|
3606
|
+
// normalize names
|
|
3463
3607
|
static eye(size) {
|
|
3464
3608
|
let result = new Matrix(size, size);
|
|
3465
3609
|
for (let i = 0; i < size; i++)
|
|
@@ -3484,6 +3628,20 @@ class Matrix{
|
|
|
3484
3628
|
for (let j = 0; j < cols; j++) result.arr[i][j] = number;
|
|
3485
3629
|
return result;
|
|
3486
3630
|
}
|
|
3631
|
+
static get Random(){
|
|
3632
|
+
return {
|
|
3633
|
+
int : (r, c, a, b)=> new Matrix(
|
|
3634
|
+
r,
|
|
3635
|
+
c,
|
|
3636
|
+
Random.sample.int(r*c, a, b)
|
|
3637
|
+
),
|
|
3638
|
+
float : (r, c, a,)=> new Matrix(
|
|
3639
|
+
r,
|
|
3640
|
+
c,
|
|
3641
|
+
Random.sample.float(r*c, a, b)
|
|
3642
|
+
),
|
|
3643
|
+
}
|
|
3644
|
+
}
|
|
3487
3645
|
hstack(...matrices) {
|
|
3488
3646
|
const M=[this, ...matrices].reduce((a,b)=>hstack(a, b));
|
|
3489
3647
|
Object.assign(this, M);
|
|
@@ -3938,21 +4096,6 @@ const matrix2=(...element)=>new Matrix(2, 2, element);
|
|
|
3938
4096
|
const matrix3=(...element)=>new Matrix(3, 3, element);
|
|
3939
4097
|
const matrix4=(...element)=>new Matrix(4, 4, element);
|
|
3940
4098
|
|
|
3941
|
-
const powerSet=originalSet=>{
|
|
3942
|
-
const subSets = [];
|
|
3943
|
-
const NUMBER_OF_COMBINATIONS = 2 ** originalSet.length;
|
|
3944
|
-
for (let i = 0; i < NUMBER_OF_COMBINATIONS; i += 1) {
|
|
3945
|
-
const subSet = [];
|
|
3946
|
-
for (let j = 0; j < originalSet.length; j += 1) {
|
|
3947
|
-
if (i & (1 << j)) {
|
|
3948
|
-
subSet.push(originalSet[j]);
|
|
3949
|
-
}
|
|
3950
|
-
}
|
|
3951
|
-
subSets.push(subSet);
|
|
3952
|
-
}
|
|
3953
|
-
return subSets;
|
|
3954
|
-
};
|
|
3955
|
-
|
|
3956
4099
|
const zeros=(n)=>new Array(n).fill(0);
|
|
3957
4100
|
const ones=(n)=>new Array(n).fill(1);
|
|
3958
4101
|
const nums=(num,n)=>new Array(n).fill(num);
|
|
@@ -4021,97 +4164,6 @@ const geomspace=(a,b,n=abs(b-a)+1,endpoint=true)=>{
|
|
|
4021
4164
|
}
|
|
4022
4165
|
};
|
|
4023
4166
|
|
|
4024
|
-
// Mixed calcul
|
|
4025
|
-
const sum=(...x)=>{
|
|
4026
|
-
if(x.every(n=>typeof n==="number")){
|
|
4027
|
-
let s = x[0];
|
|
4028
|
-
for (let i = 1; i < x.length; i++) s += x[i];
|
|
4029
|
-
return s;
|
|
4030
|
-
}
|
|
4031
|
-
const Y=[];
|
|
4032
|
-
for(let i=0;i<x.length;i++){
|
|
4033
|
-
if(x[i] instanceof Array)Y.push(sum(...x[i]));
|
|
4034
|
-
else if(x[i] instanceof Object){
|
|
4035
|
-
Y.push(sum(...Object.values(x[i])));
|
|
4036
|
-
}
|
|
4037
|
-
}
|
|
4038
|
-
return Y.length===1?Y[0]:Y;
|
|
4039
|
-
};
|
|
4040
|
-
const prod=(...x)=>{
|
|
4041
|
-
if(x.every(n=>typeof n==="number")){
|
|
4042
|
-
let p = x[0];
|
|
4043
|
-
for (let i = 1; i < x.length; i++) p *= x[i];
|
|
4044
|
-
return p;
|
|
4045
|
-
}
|
|
4046
|
-
const Y=[];
|
|
4047
|
-
for(let i=0;i<x.length;i++){
|
|
4048
|
-
if(x[i] instanceof Array)Y.push(prod(...x[i]));
|
|
4049
|
-
else if(x[i] instanceof Object){
|
|
4050
|
-
Y.push(prod(...Object.values(x[i])));
|
|
4051
|
-
}
|
|
4052
|
-
}
|
|
4053
|
-
return Y.length===1?Y[0]:Y;
|
|
4054
|
-
};
|
|
4055
|
-
// const min=(...num)=>{
|
|
4056
|
-
// if(num.every(n=>typeof n==="number"))return Math.min(...num);
|
|
4057
|
-
// const Y=[];
|
|
4058
|
-
// for(let i=0;i<num.length;i++){
|
|
4059
|
-
// if(num[i] instanceof Array)Y.push(min(...num[i]));
|
|
4060
|
-
// else if(num[i] instanceof Object){
|
|
4061
|
-
// Y.push(
|
|
4062
|
-
// Object.fromEntries(
|
|
4063
|
-
// [Object.entries(num[i]).sort((a,b)=>a[1]-b[1])[0]]
|
|
4064
|
-
// )
|
|
4065
|
-
// )
|
|
4066
|
-
// }
|
|
4067
|
-
// }
|
|
4068
|
-
// return Y.length===1?Y[0]:Y;
|
|
4069
|
-
// }
|
|
4070
|
-
// const max=(...num)=>{
|
|
4071
|
-
// if(num.every(n=>typeof n==="number"))return Math.max(...num);
|
|
4072
|
-
// const Y=[];
|
|
4073
|
-
// for(let i=0;i<num.length;i++){
|
|
4074
|
-
// if(num[i] instanceof Array)Y.push(min(...num[i]));
|
|
4075
|
-
// else if(num[i] instanceof Object){
|
|
4076
|
-
// Y.push(
|
|
4077
|
-
// Object.fromEntries(
|
|
4078
|
-
// [Object.entries(num[i]).sort((a,b)=>b[1]-a[1])[0]]
|
|
4079
|
-
// )
|
|
4080
|
-
// )
|
|
4081
|
-
// }
|
|
4082
|
-
// }
|
|
4083
|
-
// return Y.length===1?Y[0]:Y;
|
|
4084
|
-
// }
|
|
4085
|
-
const accum=(...num)=>{
|
|
4086
|
-
if(num.every(n=>typeof n==="number")){
|
|
4087
|
-
let acc = num.reduce((x, y) => [...x, x[x.length - 1] + y], [0]);
|
|
4088
|
-
acc.shift();
|
|
4089
|
-
return acc;
|
|
4090
|
-
}
|
|
4091
|
-
const Y=[];
|
|
4092
|
-
for(let i=0;i<num.length;i++){
|
|
4093
|
-
if(num[i] instanceof Array)Y.push(accum(...num[i]));
|
|
4094
|
-
else if(num[i] instanceof Object){
|
|
4095
|
-
Y.push(null
|
|
4096
|
-
// Object.fromEntries(
|
|
4097
|
-
// [Object.entries(num[i]).sort((a,b)=>b[1]-a[1])[0]]
|
|
4098
|
-
// )
|
|
4099
|
-
);
|
|
4100
|
-
}
|
|
4101
|
-
}
|
|
4102
|
-
return Y.length===1?Y[0]:Y;
|
|
4103
|
-
};
|
|
4104
|
-
|
|
4105
|
-
//moy
|
|
4106
|
-
//med
|
|
4107
|
-
//variance
|
|
4108
|
-
//std
|
|
4109
|
-
//mode
|
|
4110
|
-
//acccum
|
|
4111
|
-
//min2max
|
|
4112
|
-
//max2min
|
|
4113
|
-
//percentile
|
|
4114
|
-
|
|
4115
4167
|
/** @module Math */
|
|
4116
4168
|
/**
|
|
4117
4169
|
* Checks if a value is within the specified range.
|
|
@@ -4224,369 +4276,6 @@ const Utils={
|
|
|
4224
4276
|
isApproximatlyEqual
|
|
4225
4277
|
};
|
|
4226
4278
|
|
|
4227
|
-
// const subSet = (...arr) => {
|
|
4228
|
-
// let list = arange(0, 2 ** arr.length, 1);
|
|
4229
|
-
// let bin = list.map((n) => n.toString(2).padStart(arr.length, '0')).map((n) => n.split("").map((n) => +n));
|
|
4230
|
-
// let sub = bin.map((n) => n.map((m, i) => (m === 1 ? arr[i] : null))).map((n) => n.filter((x) => x !== null));
|
|
4231
|
-
// return sub;
|
|
4232
|
-
// };
|
|
4233
|
-
const subSet = null;
|
|
4234
|
-
|
|
4235
|
-
const Base={
|
|
4236
|
-
_mode:Number,
|
|
4237
|
-
_map:function(func,number,toBase){
|
|
4238
|
-
if (number instanceof Matrix)
|
|
4239
|
-
return new Matrix(
|
|
4240
|
-
number.rows,
|
|
4241
|
-
number.cols,
|
|
4242
|
-
number.arr.flat(1).map(n=>func(n,toBase))
|
|
4243
|
-
);
|
|
4244
|
-
else if (number instanceof Complex) return new Complex(func(number.a,toBase),func(number.b,toBase));
|
|
4245
|
-
else if (number instanceof Array) return number.map((n) =>func(n,toBase));
|
|
4246
|
-
},
|
|
4247
|
-
dec2base(dec,base){
|
|
4248
|
-
base<=10?this._mode=Number:this._mode=String;
|
|
4249
|
-
//this._mode=String
|
|
4250
|
-
if (typeof dec === "number") return this._mode((dec >>> 0).toString(base));
|
|
4251
|
-
return this._map(this.dec2base,dec,base)
|
|
4252
|
-
},
|
|
4253
|
-
dec2bin(dec){
|
|
4254
|
-
return this.dec2base(dec,2);
|
|
4255
|
-
},
|
|
4256
|
-
dec2oct(dec){
|
|
4257
|
-
return this.dec2base(dec,8);
|
|
4258
|
-
},
|
|
4259
|
-
dec2hex(dec){
|
|
4260
|
-
return this.dec2base(dec,16);
|
|
4261
|
-
},
|
|
4262
|
-
bin2base(bin, base) {
|
|
4263
|
-
return this.dec2base(this.bin2dec(bin),base)
|
|
4264
|
-
},
|
|
4265
|
-
bin2dec(bin){
|
|
4266
|
-
return this._mode("0b"+bin);
|
|
4267
|
-
},
|
|
4268
|
-
bin2oct(bin){
|
|
4269
|
-
return this.bin2base(bin,8);
|
|
4270
|
-
},
|
|
4271
|
-
bin2hex(bin){
|
|
4272
|
-
return this.bin2base(bin,16);
|
|
4273
|
-
},
|
|
4274
|
-
oct2dec(oct){
|
|
4275
|
-
return this._mode("0o"+oct);
|
|
4276
|
-
},
|
|
4277
|
-
oct2bin(oct){
|
|
4278
|
-
return this.dec2bin(this.oct2dec(oct))
|
|
4279
|
-
},
|
|
4280
|
-
oct2hex(oct){
|
|
4281
|
-
return this.dec2hex(this.oct2dec(oct))
|
|
4282
|
-
},
|
|
4283
|
-
oct2base(oct, base) {
|
|
4284
|
-
return this.dec2base(this.oct2dec(oct),base)
|
|
4285
|
-
},
|
|
4286
|
-
hex2dec(hex){
|
|
4287
|
-
return this._mode("0x"+hex);
|
|
4288
|
-
},
|
|
4289
|
-
hex2bin(hex){
|
|
4290
|
-
return this.dec2bin(this.hex2dec(hex))
|
|
4291
|
-
},
|
|
4292
|
-
hex2oct(hex){
|
|
4293
|
-
return this.dec2oct(this.hex2dec(hex))
|
|
4294
|
-
},
|
|
4295
|
-
hex2base(hex, base) {
|
|
4296
|
-
return this.dec2base(this.hex2dec(hex),base)
|
|
4297
|
-
},
|
|
4298
|
-
IEEE32toDec(Bin){
|
|
4299
|
-
let IEEE32=Bin.split(" ").join("").padEnd(32,"0");
|
|
4300
|
-
let s=IEEE32[0];
|
|
4301
|
-
let e=2**(+("0b"+IEEE32.slice(1,9))-127);
|
|
4302
|
-
let m=IEEE32.slice(9,32).split("").map(n=>+n);
|
|
4303
|
-
let M=m.map((n,i)=>n*(2**(-i-1))).reduce((a,b)=>a+b,0);
|
|
4304
|
-
let dec=(-1)**s*(1+M)*e;
|
|
4305
|
-
return dec
|
|
4306
|
-
},
|
|
4307
|
-
IEEE64toDec(Bin){
|
|
4308
|
-
let IEEE64=Bin.split(" ").join("").padEnd(64,"0");
|
|
4309
|
-
let s=IEEE64[0];
|
|
4310
|
-
let e=2**(+("0b"+IEEE64.slice(1,12))-1023);
|
|
4311
|
-
let m=IEEE64.slice(13,64).split("").map(n=>+n);
|
|
4312
|
-
let M=m.map((n,i)=>n*(2**(-i-1))).reduce((a,b)=>a+b,0);
|
|
4313
|
-
let dec=(-1)**s*(1+M)*e;
|
|
4314
|
-
return dec;
|
|
4315
|
-
}
|
|
4316
|
-
};
|
|
4317
|
-
|
|
4318
|
-
const Logic$1={
|
|
4319
|
-
_mode:Number,
|
|
4320
|
-
_map:function(func,a,b){
|
|
4321
|
-
if (a instanceof Matrix)
|
|
4322
|
-
return new Matrix(
|
|
4323
|
-
a.rows,
|
|
4324
|
-
a.cols,
|
|
4325
|
-
a.arr.flat(1).map((n) => func(n, b))
|
|
4326
|
-
);
|
|
4327
|
-
else if (a instanceof Complex) return new Complex(func(a.a, b), func(a.b, b));
|
|
4328
|
-
else if (a instanceof Array) return a.map((n) => func(n, b));
|
|
4329
|
-
},
|
|
4330
|
-
not:function(input){
|
|
4331
|
-
if(["number","boolean"].includes(typeof input)) return Logic$1._mode(!input);
|
|
4332
|
-
else return this._map(this.not,input)
|
|
4333
|
-
},
|
|
4334
|
-
and:function(a, ...b){
|
|
4335
|
-
if(["number","boolean"].includes(typeof a))return Logic$1._mode(b.reduce((n, m) => (n &= m), a));
|
|
4336
|
-
else return this._map(this.and,a,b)
|
|
4337
|
-
},
|
|
4338
|
-
or:function(a, ...b) {
|
|
4339
|
-
if(["number","boolean"].includes(typeof a)) return Logic$1._mode(b.reduce((n, m) => (n |= m), a));
|
|
4340
|
-
else return this._map(this.or,a,b);
|
|
4341
|
-
},
|
|
4342
|
-
nand:function(a, ...b) {
|
|
4343
|
-
return this.not(this.and(a, b));
|
|
4344
|
-
},
|
|
4345
|
-
nor:function(a, ...b) {
|
|
4346
|
-
return this.not(this.or(a, b));
|
|
4347
|
-
},
|
|
4348
|
-
xor:function(a,...b){
|
|
4349
|
-
let arr=[a,...b];
|
|
4350
|
-
if(["number","boolean"].includes(typeof a))return this._mode(arr.reduce((length,cur)=>{
|
|
4351
|
-
if(+cur===1)length+=1;
|
|
4352
|
-
return length;
|
|
4353
|
-
},0)===1);
|
|
4354
|
-
else return this._map(this.xor,a,b);
|
|
4355
|
-
},
|
|
4356
|
-
xnor:function(a,...b){
|
|
4357
|
-
return Logic$1.not(Logic$1.xor(a,b))
|
|
4358
|
-
}
|
|
4359
|
-
|
|
4360
|
-
};
|
|
4361
|
-
|
|
4362
|
-
class Permutation {
|
|
4363
|
-
static withDiscount(arr, l = arr.length) {
|
|
4364
|
-
if (l === 1) return arr.map((n) => [n]);
|
|
4365
|
-
const permutations = [];
|
|
4366
|
-
let smallerPermutations;
|
|
4367
|
-
smallerPermutations = this.withDiscount(arr, l - 1);
|
|
4368
|
-
arr.forEach((currentOption) => {
|
|
4369
|
-
smallerPermutations.forEach((smallerPermutation) => {
|
|
4370
|
-
permutations.push([currentOption].concat(smallerPermutation));
|
|
4371
|
-
});
|
|
4372
|
-
});
|
|
4373
|
-
return permutations;
|
|
4374
|
-
}
|
|
4375
|
-
static withoutDiscount(arr) {
|
|
4376
|
-
const l = arr.length;
|
|
4377
|
-
if (l === 1) return arr.map((n) => [n]);
|
|
4378
|
-
const permutations = [];
|
|
4379
|
-
const smallerPermutations = this.withoutDiscount(arr.slice(1));
|
|
4380
|
-
const firstOption = arr[0];
|
|
4381
|
-
for (let i = 0; i < smallerPermutations.length; i++) {
|
|
4382
|
-
const smallerPermutation = smallerPermutations[i];
|
|
4383
|
-
for (let j = 0; j <= smallerPermutation.length; j++) {
|
|
4384
|
-
const permutationPrefix = smallerPermutation.slice(0, j);
|
|
4385
|
-
const permutationSuffix = smallerPermutation.slice(j);
|
|
4386
|
-
permutations.push(permutationPrefix.concat([firstOption], permutationSuffix));
|
|
4387
|
-
}
|
|
4388
|
-
}
|
|
4389
|
-
return permutations;
|
|
4390
|
-
}
|
|
4391
|
-
}
|
|
4392
|
-
|
|
4393
|
-
class Combinaison {
|
|
4394
|
-
static withDiscount(comboOptions, comboLength) {
|
|
4395
|
-
if (comboLength === 1) {
|
|
4396
|
-
return comboOptions.map((comboOption) => [comboOption]);
|
|
4397
|
-
}
|
|
4398
|
-
const combos = [];
|
|
4399
|
-
comboOptions.forEach((currentOption, optionIndex) => {
|
|
4400
|
-
const smallerCombos = this.withDiscount(comboOptions.slice(optionIndex), comboLength - 1);
|
|
4401
|
-
smallerCombos.forEach((smallerCombo) => {
|
|
4402
|
-
combos.push([currentOption].concat(smallerCombo));
|
|
4403
|
-
});
|
|
4404
|
-
});
|
|
4405
|
-
return combos;
|
|
4406
|
-
}
|
|
4407
|
-
static withoutDiscount(comboOptions, comboLength) {
|
|
4408
|
-
if (comboLength === 1) {
|
|
4409
|
-
return comboOptions.map((comboOption) => [comboOption]);
|
|
4410
|
-
}
|
|
4411
|
-
const combos = [];
|
|
4412
|
-
comboOptions.forEach((currentOption, optionIndex) => {
|
|
4413
|
-
const smallerCombos = this.withoutDiscount(comboOptions.slice(optionIndex + 1), comboLength - 1);
|
|
4414
|
-
smallerCombos.forEach((smallerCombo) => {
|
|
4415
|
-
combos.push([currentOption].concat(smallerCombo));
|
|
4416
|
-
});
|
|
4417
|
-
});
|
|
4418
|
-
|
|
4419
|
-
return combos;
|
|
4420
|
-
}
|
|
4421
|
-
}
|
|
4422
|
-
const combinaison=(comboOptions, comboLength, discount=false)=>Combinaison[discount?"withDiscount":"withoutDiscount"](comboOptions, comboLength);
|
|
4423
|
-
|
|
4424
|
-
class Random {
|
|
4425
|
-
static float(a = 1, b) {
|
|
4426
|
-
return b ? Math.random() * (b - a) + a : a * Math.random();
|
|
4427
|
-
}
|
|
4428
|
-
static int(a, b) {
|
|
4429
|
-
return Math.floor(this.float(a, b));
|
|
4430
|
-
}
|
|
4431
|
-
static char(upperCase){
|
|
4432
|
-
upperCase=upperCase??this.bool();
|
|
4433
|
-
const Char=String.fromCharCode(this.int(97,120));
|
|
4434
|
-
return upperCase?Char.toUpperCase():Char;
|
|
4435
|
-
}
|
|
4436
|
-
static bool(){
|
|
4437
|
-
return [false,true][Math.floor(Math.random()*2)];
|
|
4438
|
-
}
|
|
4439
|
-
static string(length,upperCase){
|
|
4440
|
-
return length instanceof Array?
|
|
4441
|
-
new Array(this.int(...length)).fill(0).map(() => this.char(upperCase)).join(""):
|
|
4442
|
-
new Array(length).fill(0).map(() => this.char(upperCase)).join("");
|
|
4443
|
-
}
|
|
4444
|
-
static bin() {
|
|
4445
|
-
return this.int(2);
|
|
4446
|
-
}
|
|
4447
|
-
static oct() {
|
|
4448
|
-
return this.int(8);
|
|
4449
|
-
}
|
|
4450
|
-
static dec() {
|
|
4451
|
-
return this.int(8);
|
|
4452
|
-
}
|
|
4453
|
-
static hex() {
|
|
4454
|
-
return this.int(16);
|
|
4455
|
-
}
|
|
4456
|
-
static choice(choices = [1, 2, 3], p = new Array(choices.length).fill(1 / choices.length)) {
|
|
4457
|
-
let newchoice = new Array(100);
|
|
4458
|
-
p=Utils.accum(...p).map(n=>n*100);
|
|
4459
|
-
newchoice.fill(choices[0], 0, p[0]);
|
|
4460
|
-
for (let i = 1; i < choices.length; i++) newchoice.fill(choices[i], p[i - 1], p[i]);
|
|
4461
|
-
return newchoice[this.int(newchoice.length - 1)];
|
|
4462
|
-
}
|
|
4463
|
-
static shuffleArr(arr){
|
|
4464
|
-
return arr.sort(()=>0.5-Math.random())
|
|
4465
|
-
}
|
|
4466
|
-
static floats(n, a, b) {
|
|
4467
|
-
return new Array(n).fill(0).map(() => this.float(a, b));
|
|
4468
|
-
}
|
|
4469
|
-
static ints(n, a, b) {
|
|
4470
|
-
return new Array(n).fill(0).map(() => this.int(a, b));
|
|
4471
|
-
}
|
|
4472
|
-
static bools(n){
|
|
4473
|
-
return new Array(n).fill(0).map(() => this.bool());
|
|
4474
|
-
}
|
|
4475
|
-
static bins(n) {
|
|
4476
|
-
return new Array(n).fill(0).map(() => this.int(2));
|
|
4477
|
-
}
|
|
4478
|
-
static octs(n) {
|
|
4479
|
-
return new Array(n).fill(0).map(() => this.int(8));
|
|
4480
|
-
}
|
|
4481
|
-
static decs(n) {
|
|
4482
|
-
return new Array(n).fill(0).map(() => this.int(10));
|
|
4483
|
-
}
|
|
4484
|
-
static hexs(n) {
|
|
4485
|
-
return new Array(n).fill(0).map(() => this.int(16));
|
|
4486
|
-
}
|
|
4487
|
-
static choices(n, choices, p) {
|
|
4488
|
-
return new Array(n).fill(0).map(() => this.choice(choices, p));
|
|
4489
|
-
}
|
|
4490
|
-
static perm(...arr) {
|
|
4491
|
-
// permutation
|
|
4492
|
-
return arr.permS[this.int(arr.length)];
|
|
4493
|
-
}
|
|
4494
|
-
static color() {
|
|
4495
|
-
return "#" + Base.dec2hex(this.float(16777216)).padStart(6,0);
|
|
4496
|
-
}
|
|
4497
|
-
static colors(n) {
|
|
4498
|
-
return new Array(n).fill(null).map(()=>this.color());
|
|
4499
|
-
}
|
|
4500
|
-
|
|
4501
|
-
// Should be Moved to Matrix and Complex to avoid Circular dependencies
|
|
4502
|
-
// static complex(a = [0,1], b = [0,1]) {
|
|
4503
|
-
// return a instanceof Array?
|
|
4504
|
-
// new Complex(
|
|
4505
|
-
// this.float(a[0], a[1]),
|
|
4506
|
-
// this.float(b[0], b[1])
|
|
4507
|
-
// ):
|
|
4508
|
-
// new Complex(
|
|
4509
|
-
// ...this.floats(2,a,b)
|
|
4510
|
-
// )
|
|
4511
|
-
|
|
4512
|
-
// }
|
|
4513
|
-
// static complexInt(a = [0,1], b = [0,1]) {
|
|
4514
|
-
// return new Complex(
|
|
4515
|
-
// this.int(a[0], a[1]),
|
|
4516
|
-
// this.int(b[0], b[1])
|
|
4517
|
-
// );
|
|
4518
|
-
// }
|
|
4519
|
-
// static complexBin() {
|
|
4520
|
-
// return new Complex(...this.bins(2));
|
|
4521
|
-
// }
|
|
4522
|
-
// static complexOct() {
|
|
4523
|
-
// return new Complex(...this.octs(2));
|
|
4524
|
-
// }
|
|
4525
|
-
// static complexDec() {
|
|
4526
|
-
// return new Complex(...this.decs(10));
|
|
4527
|
-
// }
|
|
4528
|
-
// static complexHex() {
|
|
4529
|
-
// return new Complex(...this.octs(2));
|
|
4530
|
-
// }
|
|
4531
|
-
// static complexes(n, a = 0, b = 1) {
|
|
4532
|
-
// return new Array(n).fill(0).map(() => this.complex(a, b));
|
|
4533
|
-
// }
|
|
4534
|
-
// static complexesInt(n, a = 0, b = 1) {
|
|
4535
|
-
// return new Array(n).fill(0).map(() => this.complexInt(a, b));
|
|
4536
|
-
// }
|
|
4537
|
-
// static complexesBin(n) {
|
|
4538
|
-
// return new Array(n).fill(0).map(() => this.complexBin());
|
|
4539
|
-
// }
|
|
4540
|
-
// static complexesOct(n) {
|
|
4541
|
-
// return new Array(n).fill(0).map(() => this.complexOct());
|
|
4542
|
-
// }
|
|
4543
|
-
// static complexesDec(n) {
|
|
4544
|
-
// return new Array(n).fill(0).map(() => this.complexDec());
|
|
4545
|
-
// }
|
|
4546
|
-
// static complexesHex(n) {
|
|
4547
|
-
// return new Array(n).fill(0).map(() => this.complexHex());
|
|
4548
|
-
// }
|
|
4549
|
-
// static matrix(r,c,min,max){
|
|
4550
|
-
// return matrix(r,c,this.floats(r*c,min,max))
|
|
4551
|
-
// }
|
|
4552
|
-
// static matrixInt(r,c,min,max){
|
|
4553
|
-
// return matrix(r,c,this.ints(r*c,min,max))
|
|
4554
|
-
// }
|
|
4555
|
-
// static matrixBin(r,c){
|
|
4556
|
-
// return matrix(r,c,this.bins(r*c))
|
|
4557
|
-
// }
|
|
4558
|
-
// static matrixOct(r,c){
|
|
4559
|
-
// return matrix(r,c,this.octs(r*c))
|
|
4560
|
-
// }
|
|
4561
|
-
// static matrixDec(r,c){
|
|
4562
|
-
// return matrix(r,c,this.decs(r*c))
|
|
4563
|
-
// }
|
|
4564
|
-
// static matrixHex(r,c){
|
|
4565
|
-
// return matrix(r,c,this.hex(r*c))
|
|
4566
|
-
// }
|
|
4567
|
-
// static matrixColor(r,c){
|
|
4568
|
-
// return matrix(r,c,this.colors(r*c))
|
|
4569
|
-
// }
|
|
4570
|
-
// static matrixComplex(r,c,a,b){
|
|
4571
|
-
// return matrix(r,c,this.complexes(r*c,a,b))
|
|
4572
|
-
// }
|
|
4573
|
-
// static matrixComplexInt(r,c,a,b){
|
|
4574
|
-
// return matrix(r,c,this.complexesInt(r*c,a,b))
|
|
4575
|
-
// }
|
|
4576
|
-
// static matrixComplexBin(r,c){
|
|
4577
|
-
// return matrix(r,c,this.complexesBin(r*c))
|
|
4578
|
-
// }
|
|
4579
|
-
// static matrixComplexOct(r,c){
|
|
4580
|
-
// return matrix(r,c,this.complexesBin(r*c))
|
|
4581
|
-
// }
|
|
4582
|
-
// static matrixComplexDec(r,c){
|
|
4583
|
-
// return matrix(r,c,this.complexesBin(r*c))
|
|
4584
|
-
// }
|
|
4585
|
-
// static matrixComplexHex(r,c){
|
|
4586
|
-
// return matrix(r,c,this.complexesBin(r*c))
|
|
4587
|
-
// }
|
|
4588
|
-
}
|
|
4589
|
-
|
|
4590
4279
|
const { PI, sqrt: sqrt$1, cos: cos$2, sin: sin$2, acos, pow } = Math;
|
|
4591
4280
|
|
|
4592
4281
|
const linear = t => t;
|
|
@@ -5743,4 +5432,4 @@ if(globalThis?.document){
|
|
|
5743
5432
|
document?.addEventListener("DOMContentLoaded", __Ziko__.__Config__.init());
|
|
5744
5433
|
}
|
|
5745
5434
|
|
|
5746
|
-
export { App,
|
|
5435
|
+
export { App, Clock, Complex, E, EPSILON, FileBasedRouting, Flex, HTMLWrapper, Matrix, PI$1 as PI, Random, SPA, SVGWrapper, Scheduler, Suspense, Switch, Tick, TimeAnimation, TimeLoop, TimeScheduler, UIElement$1 as UIElement, UIHTMLWrapper, UINode, UISVGWrapper, UISwitch, UIView, UseRoot, UseThread, Utils, View, ZikoApp, ZikoEvent, ZikoSPA, ZikoUIFlex, ZikoUISuspense, ZikoUIText, abs, accum_prod, accum_sum, acos$1 as acos, acosh, acot, add, and, animation, apply_fun, arange, arc, arr2str, asin, asinh, atan, atan2, atanh, back, bind_click_event, bind_clipboard_event, bind_drag_event, bind_focus_event, bind_key_event, bind_mouse_event, bind_pointer_event, bind_swipe_event, bind_touch_event, bind_view_event, bind_wheel_event, binomial, cartesianProduct, cbrt, ceil, clamp, clock, complex, cos$3 as cos, cosh$2 as cosh, coth, croot, csv2arr, csv2json, csv2matrix, csv2object, csv2sql, debounce, defineParamsGetter, define_wc, deg2rad, discret, div, elastic, event_controller, exp$1 as exp, floor, fract, geomspace, getEvent, hypot, inRange, in_back, in_bounce, in_circ, in_cubic, in_elastic, in_expo, in_out_back, in_out_bounce, in_out_circ, in_out_cubic, in_out_elastic, in_out_expo, in_out_quad, in_out_quart, in_out_quint, in_out_sin, in_quad, in_quart, in_quint, in_sin, isApproximatlyEqual, isStateGetter, json2arr, json2css, json2csv, json2csvFile, json2xml, json2xmlFile, json2yml, json2ymlFile, lerp, linear, linspace, ln, logspace, loop, map$1 as map, mapfun, matrix, matrix2, matrix3, matrix4, max$1 as max, mean, median, min$1 as min, modulo, mul, nand, nor, norm, nthr, nums, obj2str, ones, or, out_back, out_bounce, out_circ, out_cubic, out_elastic, out_expo, out_quad, out_quart, out_quint, out_sin, percentile, pgcd, pow$1 as pow, ppcm, preload, rad2deg, round, sec, sig, sign, sin$3 as sin, sinh$1 as sinh, sleep, sqrt$2 as sqrt, std, step, step_fps, sub, svg2ascii, svg2img, svg2imgUrl, svg2str, tags, tan, tanh, text, throttle, tick, timeTaken, time_memory_Taken, timeout, toggle_event_listener, trunc, useDerived, useEventEmitter, useIPC, useLocaleStorage, useMediaQuery, useReactive, useRoot, useSessionStorage, useState, useThread, useTitle, variance, wait, waitForUIElm, waitForUIElmSync, xnor, xor, zeros };
|