umt 2.6.0 → 2.8.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/README.md +25 -0
- package/module/Crypto/decodeBase32.d.ts +7 -0
- package/module/Crypto/decodeBase32.js +27 -0
- package/module/Crypto/decodeBase32.js.map +1 -0
- package/module/Crypto/decodeBase32ToString.d.ts +7 -0
- package/module/Crypto/decodeBase32ToString.js +11 -0
- package/module/Crypto/decodeBase32ToString.js.map +1 -0
- package/module/Crypto/decodeBase58.d.ts +7 -0
- package/module/Crypto/decodeBase58.js +34 -0
- package/module/Crypto/decodeBase58.js.map +1 -0
- package/module/Crypto/decodeBase58ToString.d.ts +7 -0
- package/module/Crypto/decodeBase58ToString.js +11 -0
- package/module/Crypto/decodeBase58ToString.js.map +1 -0
- package/module/Crypto/encodeBase32.d.ts +7 -0
- package/module/Crypto/encodeBase32.js +28 -0
- package/module/Crypto/encodeBase32.js.map +1 -0
- package/module/Crypto/encodeBase58.d.ts +7 -0
- package/module/Crypto/encodeBase58.js +29 -0
- package/module/Crypto/encodeBase58.js.map +1 -0
- package/module/Crypto/index.d.ts +6 -0
- package/module/Crypto/index.js +7 -0
- package/module/Crypto/index.js.map +1 -0
- package/module/DataStructure/index.d.ts +1 -0
- package/module/DataStructure/index.js +2 -0
- package/module/DataStructure/index.js.map +1 -0
- package/module/DataStructure/priorityQueue.d.ts +241 -0
- package/module/DataStructure/priorityQueue.js +327 -0
- package/module/DataStructure/priorityQueue.js.map +1 -0
- package/module/Math/correlationCoefficient.d.ts +11 -0
- package/module/Math/correlationCoefficient.js +40 -0
- package/module/Math/correlationCoefficient.js.map +1 -0
- package/module/Math/index.d.ts +3 -0
- package/module/Math/index.js +3 -0
- package/module/Math/index.js.map +1 -1
- package/module/Math/mode.d.ts +10 -0
- package/module/Math/mode.js +31 -0
- package/module/Math/mode.js.map +1 -0
- package/module/Math/percentile.d.ts +11 -0
- package/module/Math/percentile.js +31 -0
- package/module/Math/percentile.js.map +1 -0
- package/module/Math/solveEquation.js +1 -1
- package/module/Math/solveEquation.js.map +1 -1
- package/module/String/fuzzySearch.d.ts +14 -0
- package/module/String/fuzzySearch.js +27 -0
- package/module/String/fuzzySearch.js.map +1 -0
- package/module/String/index.d.ts +4 -0
- package/module/String/index.js +4 -0
- package/module/String/index.js.map +1 -1
- package/module/String/reverseString.js +1 -1
- package/module/String/reverseString.js.map +1 -1
- package/module/String/slugify.d.ts +10 -0
- package/module/String/slugify.js +21 -0
- package/module/String/slugify.js.map +1 -0
- package/module/String/truncate.d.ts +12 -0
- package/module/String/truncate.js +21 -0
- package/module/String/truncate.js.map +1 -0
- package/module/String/unescapeHtml.d.ts +17 -0
- package/module/String/unescapeHtml.js +45 -0
- package/module/String/unescapeHtml.js.map +1 -0
- package/module/Validate/index.d.ts +1 -0
- package/module/Validate/index.js +1 -0
- package/module/Validate/index.js.map +1 -1
- package/module/Validate/isDeepEqual.d.ts +28 -0
- package/module/Validate/isDeepEqual.js +148 -0
- package/module/Validate/isDeepEqual.js.map +1 -0
- package/module/Validate/isNode.js +3 -2
- package/module/Validate/isNode.js.map +1 -1
- package/module/Validate/string/email.js +8 -0
- package/module/Validate/string/email.js.map +1 -1
- package/module/es5/Crypto/decodeBase32.d.ts +7 -0
- package/module/es5/Crypto/decodeBase32.js +44 -0
- package/module/es5/Crypto/decodeBase32ToString.d.ts +7 -0
- package/module/es5/Crypto/decodeBase32ToString.js +16 -0
- package/module/es5/Crypto/decodeBase58.d.ts +7 -0
- package/module/es5/Crypto/decodeBase58.js +63 -0
- package/module/es5/Crypto/decodeBase58ToString.d.ts +7 -0
- package/module/es5/Crypto/decodeBase58ToString.js +16 -0
- package/module/es5/Crypto/encodeBase32.d.ts +7 -0
- package/module/es5/Crypto/encodeBase32.js +45 -0
- package/module/es5/Crypto/encodeBase58.d.ts +7 -0
- package/module/es5/Crypto/encodeBase58.js +55 -0
- package/module/es5/Crypto/index.d.ts +6 -0
- package/module/es5/Crypto/index.js +71 -0
- package/module/es5/DataStructure/index.d.ts +1 -0
- package/module/es5/DataStructure/index.js +16 -0
- package/module/es5/DataStructure/priorityQueue.d.ts +241 -0
- package/module/es5/DataStructure/priorityQueue.js +405 -0
- package/module/es5/Error/retry.js +2 -2
- package/module/es5/Math/correlationCoefficient.d.ts +11 -0
- package/module/es5/Math/correlationCoefficient.js +63 -0
- package/module/es5/Math/index.d.ts +3 -0
- package/module/es5/Math/index.js +33 -0
- package/module/es5/Math/mode.d.ts +10 -0
- package/module/es5/Math/mode.js +67 -0
- package/module/es5/Math/percentile.d.ts +11 -0
- package/module/es5/Math/percentile.js +42 -0
- package/module/es5/Math/solveEquation.js +1 -1
- package/module/es5/String/fuzzySearch.d.ts +14 -0
- package/module/es5/String/fuzzySearch.js +50 -0
- package/module/es5/String/index.d.ts +4 -0
- package/module/es5/String/index.js +44 -0
- package/module/es5/String/reverseString.js +1 -1
- package/module/es5/String/slugify.d.ts +10 -0
- package/module/es5/String/slugify.js +18 -0
- package/module/es5/String/truncate.d.ts +12 -0
- package/module/es5/String/truncate.js +27 -0
- package/module/es5/String/unescapeHtml.d.ts +17 -0
- package/module/es5/String/unescapeHtml.js +51 -0
- package/module/es5/Validate/index.d.ts +1 -0
- package/module/es5/Validate/index.js +11 -0
- package/module/es5/Validate/isDeepEqual.d.ts +28 -0
- package/module/es5/Validate/isDeepEqual.js +232 -0
- package/module/es5/Validate/isNode.js +5 -2
- package/module/es5/Validate/string/email.js +10 -0
- package/module/es5/index.d.ts +2 -0
- package/module/es5/index.js +22 -0
- package/module/es5/tsconfig.tsbuildinfo +1 -1
- package/module/index.d.ts +2 -0
- package/module/index.js +2 -0
- package/module/index.js.map +1 -1
- package/package.json +31 -31
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.PriorityQueue = void 0;
|
|
7
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
8
|
+
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
9
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
10
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
11
|
+
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
12
|
+
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
13
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
14
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
15
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
16
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
17
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
18
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
19
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
20
|
+
/**
|
|
21
|
+
* A priority queue implementation using a binary heap.
|
|
22
|
+
* Higher priority values are dequeued first.
|
|
23
|
+
*
|
|
24
|
+
* ## Features
|
|
25
|
+
* - **enqueue(value, priority)**: Add element with priority
|
|
26
|
+
* - **enqueueBack(value)**: Add element to the back with lowest priority
|
|
27
|
+
* - **dequeue()**: Remove and return highest priority element
|
|
28
|
+
* - **peek()**: View highest priority element without removing
|
|
29
|
+
* - **peekPriority()**: View highest priority value
|
|
30
|
+
* - **size**: Get number of elements
|
|
31
|
+
* - **isEmpty**: Check if queue is empty
|
|
32
|
+
* - **clear()**: Remove all elements
|
|
33
|
+
* - **toArray()**: Get all elements as array
|
|
34
|
+
* - **toArrayWithPriorities()**: Get all elements with priorities
|
|
35
|
+
*
|
|
36
|
+
* ## Time Complexity
|
|
37
|
+
* - enqueue: O(log n)
|
|
38
|
+
* - enqueueBack: O(log n)
|
|
39
|
+
* - dequeue: O(log n)
|
|
40
|
+
* - peek: O(1)
|
|
41
|
+
* - peekPriority: O(1)
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* const queue = new PriorityQueue<string>();
|
|
46
|
+
* queue.enqueue("low", 1);
|
|
47
|
+
* queue.enqueue("high", 3);
|
|
48
|
+
* queue.enqueue("medium", 2);
|
|
49
|
+
*
|
|
50
|
+
* console.log(queue.dequeue()); // "high"
|
|
51
|
+
* console.log(queue.dequeue()); // "medium"
|
|
52
|
+
* console.log(queue.dequeue()); // "low"
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* // Initialize with elements
|
|
58
|
+
* const queue = new PriorityQueue([
|
|
59
|
+
* { value: "task1", priority: 1 },
|
|
60
|
+
* { value: "task2", priority: 3 },
|
|
61
|
+
* { value: "task3", priority: 2 }
|
|
62
|
+
* ]);
|
|
63
|
+
*
|
|
64
|
+
* console.log(queue.peek()); // "task2"
|
|
65
|
+
* console.log(queue.peekPriority()); // 3
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* @template T - The type of elements stored in the queue
|
|
69
|
+
*/
|
|
70
|
+
var PriorityQueue = exports.PriorityQueue = /*#__PURE__*/function () {
|
|
71
|
+
/**
|
|
72
|
+
* Creates a new PriorityQueue instance.
|
|
73
|
+
* @param initialElements - Optional array of initial elements with priorities
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* const queue = new PriorityQueue<string>();
|
|
77
|
+
* // or
|
|
78
|
+
* const queue = new PriorityQueue([
|
|
79
|
+
* { value: "item1", priority: 10 },
|
|
80
|
+
* { value: "item2", priority: 5 }
|
|
81
|
+
* ]);
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
function PriorityQueue(initialElements) {
|
|
85
|
+
_classCallCheck(this, PriorityQueue);
|
|
86
|
+
_defineProperty(this, "heap", []);
|
|
87
|
+
_defineProperty(this, "minPriority", 0);
|
|
88
|
+
if (initialElements) {
|
|
89
|
+
this.heap = _toConsumableArray(initialElements);
|
|
90
|
+
this.updateMinPriority();
|
|
91
|
+
this.buildHeap();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Returns the number of elements in the queue.
|
|
97
|
+
* @returns The number of elements in the queue
|
|
98
|
+
* @example
|
|
99
|
+
* ```typescript
|
|
100
|
+
* const queue = new PriorityQueue<string>();
|
|
101
|
+
* queue.enqueue("item", 1);
|
|
102
|
+
* console.log(queue.size); // 1
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
return _createClass(PriorityQueue, [{
|
|
106
|
+
key: "size",
|
|
107
|
+
get: function get() {
|
|
108
|
+
return this.heap.length;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Checks if the queue is empty.
|
|
113
|
+
* @returns True if the queue is empty, false otherwise
|
|
114
|
+
* @example
|
|
115
|
+
* ```typescript
|
|
116
|
+
* const queue = new PriorityQueue<string>();
|
|
117
|
+
* console.log(queue.isEmpty); // true
|
|
118
|
+
* queue.enqueue("item", 1);
|
|
119
|
+
* console.log(queue.isEmpty); // false
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
}, {
|
|
123
|
+
key: "isEmpty",
|
|
124
|
+
get: function get() {
|
|
125
|
+
return this.heap.length === 0;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Adds an element to the queue with a specified priority.
|
|
130
|
+
* Higher priority values are dequeued first.
|
|
131
|
+
* @param value - The value to add
|
|
132
|
+
* @param priority - The priority value (higher values have higher priority)
|
|
133
|
+
* @example
|
|
134
|
+
* ```typescript
|
|
135
|
+
* const queue = new PriorityQueue<string>();
|
|
136
|
+
* queue.enqueue("low", 1);
|
|
137
|
+
* queue.enqueue("high", 10);
|
|
138
|
+
* queue.enqueue("medium", 5);
|
|
139
|
+
* console.log(queue.dequeue()); // "high"
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
}, {
|
|
143
|
+
key: "enqueue",
|
|
144
|
+
value: function enqueue(value, priority) {
|
|
145
|
+
this.heap.push({
|
|
146
|
+
value: value,
|
|
147
|
+
priority: priority
|
|
148
|
+
});
|
|
149
|
+
this.updateMinPriorityOnAdd(priority);
|
|
150
|
+
this.heapifyUp(this.heap.length - 1);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Adds an element to the end of the queue with lowest priority.
|
|
155
|
+
* This element will be dequeued last (FIFO for equal lowest priority).
|
|
156
|
+
*
|
|
157
|
+
* @param value - The value to add
|
|
158
|
+
* @example
|
|
159
|
+
* ```typescript
|
|
160
|
+
* const queue = new PriorityQueue<string>();
|
|
161
|
+
* queue.enqueue("high", 10);
|
|
162
|
+
* queue.enqueue("medium", 5);
|
|
163
|
+
* queue.enqueueBack("back1");
|
|
164
|
+
* queue.enqueueBack("back2");
|
|
165
|
+
* console.log(queue.dequeue()); // "high"
|
|
166
|
+
* console.log(queue.dequeue()); // "medium"
|
|
167
|
+
* console.log(queue.dequeue()); // "back1"
|
|
168
|
+
* console.log(queue.dequeue()); // "back2"
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
}, {
|
|
172
|
+
key: "enqueueBack",
|
|
173
|
+
value: function enqueueBack(value) {
|
|
174
|
+
var newPriority = this.minPriority - 1;
|
|
175
|
+
this.heap.push({
|
|
176
|
+
value: value,
|
|
177
|
+
priority: newPriority
|
|
178
|
+
});
|
|
179
|
+
this.minPriority = newPriority;
|
|
180
|
+
this.heapifyUp(this.heap.length - 1);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Removes and returns the element with the highest priority.
|
|
185
|
+
* @returns The element with highest priority, or undefined if queue is empty
|
|
186
|
+
* @example
|
|
187
|
+
* ```typescript
|
|
188
|
+
* const queue = new PriorityQueue<string>();
|
|
189
|
+
* queue.enqueue("low", 1);
|
|
190
|
+
* queue.enqueue("high", 10);
|
|
191
|
+
* console.log(queue.dequeue()); // "high"
|
|
192
|
+
* console.log(queue.dequeue()); // "low"
|
|
193
|
+
* console.log(queue.dequeue()); // undefined
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
}, {
|
|
197
|
+
key: "dequeue",
|
|
198
|
+
value: function dequeue() {
|
|
199
|
+
if (this.heap.length === 0) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
if (this.heap.length === 1) {
|
|
203
|
+
var _this$heap$pop;
|
|
204
|
+
return (_this$heap$pop = this.heap.pop()) === null || _this$heap$pop === void 0 ? void 0 : _this$heap$pop.value;
|
|
205
|
+
}
|
|
206
|
+
var result = this.heap[0].value;
|
|
207
|
+
// biome-ignore lint/style/noNonNullAssertion: pop() cannot return undefined when heap.length > 1
|
|
208
|
+
this.heap[0] = this.heap.pop();
|
|
209
|
+
this.heapifyDown(0);
|
|
210
|
+
return result;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Returns the element with the highest priority without removing it.
|
|
215
|
+
* @returns The element with highest priority, or undefined if queue is empty
|
|
216
|
+
* @example
|
|
217
|
+
* ```typescript
|
|
218
|
+
* const queue = new PriorityQueue<string>();
|
|
219
|
+
* queue.enqueue("low", 1);
|
|
220
|
+
* queue.enqueue("high", 10);
|
|
221
|
+
* console.log(queue.peek()); // "high"
|
|
222
|
+
* console.log(queue.size); // 2 (element not removed)
|
|
223
|
+
* ```
|
|
224
|
+
*/
|
|
225
|
+
}, {
|
|
226
|
+
key: "peek",
|
|
227
|
+
value: function peek() {
|
|
228
|
+
var _this$heap$;
|
|
229
|
+
return (_this$heap$ = this.heap[0]) === null || _this$heap$ === void 0 ? void 0 : _this$heap$.value;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Returns the priority of the element with the highest priority.
|
|
234
|
+
* @returns The highest priority value, or undefined if queue is empty
|
|
235
|
+
* @example
|
|
236
|
+
* ```typescript
|
|
237
|
+
* const queue = new PriorityQueue<string>();
|
|
238
|
+
* queue.enqueue("low", 1);
|
|
239
|
+
* queue.enqueue("high", 10);
|
|
240
|
+
* console.log(queue.peekPriority()); // 10
|
|
241
|
+
* ```
|
|
242
|
+
*/
|
|
243
|
+
}, {
|
|
244
|
+
key: "peekPriority",
|
|
245
|
+
value: function peekPriority() {
|
|
246
|
+
var _this$heap$2;
|
|
247
|
+
return (_this$heap$2 = this.heap[0]) === null || _this$heap$2 === void 0 ? void 0 : _this$heap$2.priority;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Removes all elements from the queue.
|
|
252
|
+
* @example
|
|
253
|
+
* ```typescript
|
|
254
|
+
* const queue = new PriorityQueue<string>();
|
|
255
|
+
* queue.enqueue("item1", 1);
|
|
256
|
+
* queue.enqueue("item2", 2);
|
|
257
|
+
* console.log(queue.size); // 2
|
|
258
|
+
* queue.clear();
|
|
259
|
+
* console.log(queue.size); // 0
|
|
260
|
+
* console.log(queue.isEmpty); // true
|
|
261
|
+
* ```
|
|
262
|
+
*/
|
|
263
|
+
}, {
|
|
264
|
+
key: "clear",
|
|
265
|
+
value: function clear() {
|
|
266
|
+
this.heap = [];
|
|
267
|
+
this.minPriority = 0;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Returns an array of all elements in the queue (without removing them).
|
|
272
|
+
* The order is not guaranteed to be sorted by priority.
|
|
273
|
+
* @returns Array of all elements in the queue
|
|
274
|
+
* @example
|
|
275
|
+
* ```typescript
|
|
276
|
+
* const queue = new PriorityQueue<string>();
|
|
277
|
+
* queue.enqueue("low", 1);
|
|
278
|
+
* queue.enqueue("high", 10);
|
|
279
|
+
* queue.enqueue("medium", 5);
|
|
280
|
+
* console.log(queue.toArray()); // ["high", "medium", "low"] (order may vary)
|
|
281
|
+
* ```
|
|
282
|
+
*/
|
|
283
|
+
}, {
|
|
284
|
+
key: "toArray",
|
|
285
|
+
value: function toArray() {
|
|
286
|
+
return this.heap.map(function (item) {
|
|
287
|
+
return item.value;
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Returns an array of all elements with their priorities.
|
|
293
|
+
* The order is not guaranteed to be sorted by priority.
|
|
294
|
+
* @returns Array of all elements with their priorities
|
|
295
|
+
* @example
|
|
296
|
+
* ```typescript
|
|
297
|
+
* const queue = new PriorityQueue<string>();
|
|
298
|
+
* queue.enqueue("low", 1);
|
|
299
|
+
* queue.enqueue("high", 10);
|
|
300
|
+
* console.log(queue.toArrayWithPriorities());
|
|
301
|
+
* // [{ value: "high", priority: 10 }, { value: "low", priority: 1 }] (order may vary)
|
|
302
|
+
* ```
|
|
303
|
+
*/
|
|
304
|
+
}, {
|
|
305
|
+
key: "toArrayWithPriorities",
|
|
306
|
+
value: function toArrayWithPriorities() {
|
|
307
|
+
return _toConsumableArray(this.heap);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Updates the minimum priority when adding elements.
|
|
312
|
+
* @param priority - The priority being added
|
|
313
|
+
*/
|
|
314
|
+
}, {
|
|
315
|
+
key: "updateMinPriorityOnAdd",
|
|
316
|
+
value: function updateMinPriorityOnAdd(priority) {
|
|
317
|
+
if (this.heap.length === 1 || priority < this.minPriority) {
|
|
318
|
+
this.minPriority = priority;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Updates the minimum priority from all elements (used in constructor).
|
|
324
|
+
*/
|
|
325
|
+
}, {
|
|
326
|
+
key: "updateMinPriority",
|
|
327
|
+
value: function updateMinPriority() {
|
|
328
|
+
if (this.heap.length === 0) {
|
|
329
|
+
this.minPriority = 0;
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
this.minPriority = Math.min.apply(Math, _toConsumableArray(this.heap.map(function (item) {
|
|
333
|
+
return item.priority;
|
|
334
|
+
})));
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Builds a max heap from the current heap array.
|
|
339
|
+
*/
|
|
340
|
+
}, {
|
|
341
|
+
key: "buildHeap",
|
|
342
|
+
value: function buildHeap() {
|
|
343
|
+
for (var index = Math.floor(this.heap.length / 2) - 1; index >= 0; index--) {
|
|
344
|
+
this.heapifyDown(index);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Moves an element up the heap to maintain heap property.
|
|
350
|
+
* @param index - The index of the element to move up
|
|
351
|
+
*/
|
|
352
|
+
}, {
|
|
353
|
+
key: "heapifyUp",
|
|
354
|
+
value: function heapifyUp(index) {
|
|
355
|
+
var currentIndex = index;
|
|
356
|
+
while (currentIndex > 0) {
|
|
357
|
+
var parentIndex = Math.floor((currentIndex - 1) / 2);
|
|
358
|
+
if (this.heap[currentIndex].priority <= this.heap[parentIndex].priority) {
|
|
359
|
+
break;
|
|
360
|
+
}
|
|
361
|
+
this.swap(currentIndex, parentIndex);
|
|
362
|
+
currentIndex = parentIndex;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Moves an element down the heap to maintain heap property.
|
|
368
|
+
* @param index - The index of the element to move down
|
|
369
|
+
*/
|
|
370
|
+
}, {
|
|
371
|
+
key: "heapifyDown",
|
|
372
|
+
value: function heapifyDown(index) {
|
|
373
|
+
var currentIndex = index;
|
|
374
|
+
while (true) {
|
|
375
|
+
var leftChild = 2 * currentIndex + 1;
|
|
376
|
+
var rightChild = 2 * currentIndex + 2;
|
|
377
|
+
var largest = currentIndex;
|
|
378
|
+
if (leftChild < this.heap.length && this.heap[leftChild].priority > this.heap[largest].priority) {
|
|
379
|
+
largest = leftChild;
|
|
380
|
+
}
|
|
381
|
+
if (rightChild < this.heap.length && this.heap[rightChild].priority > this.heap[largest].priority) {
|
|
382
|
+
largest = rightChild;
|
|
383
|
+
}
|
|
384
|
+
if (largest === currentIndex) {
|
|
385
|
+
break;
|
|
386
|
+
}
|
|
387
|
+
this.swap(currentIndex, largest);
|
|
388
|
+
currentIndex = largest;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Swaps two elements in the heap.
|
|
394
|
+
* @param i - First index
|
|
395
|
+
* @param j - Second index
|
|
396
|
+
*/
|
|
397
|
+
}, {
|
|
398
|
+
key: "swap",
|
|
399
|
+
value: function swap(index, index_) {
|
|
400
|
+
var _ref = [this.heap[index_], this.heap[index]];
|
|
401
|
+
this.heap[index] = _ref[0];
|
|
402
|
+
this.heap[index_] = _ref[1];
|
|
403
|
+
}
|
|
404
|
+
}]);
|
|
405
|
+
}();
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.retry = void 0;
|
|
7
7
|
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
|
|
8
|
-
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) {
|
|
8
|
+
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
|
|
9
9
|
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
10
10
|
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
|
11
11
|
/**
|
|
@@ -53,7 +53,7 @@ var retry = exports.retry = function retry(function_) {
|
|
|
53
53
|
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(remainingAttempts) {
|
|
54
54
|
var _t;
|
|
55
55
|
return _regenerator().w(function (_context) {
|
|
56
|
-
while (1) switch (_context.n) {
|
|
56
|
+
while (1) switch (_context.p = _context.n) {
|
|
57
57
|
case 0:
|
|
58
58
|
_context.p = 0;
|
|
59
59
|
_context.n = 1;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculate the Pearson correlation coefficient between two arrays
|
|
3
|
+
* @param x - First array of numbers
|
|
4
|
+
* @param y - Second array of numbers
|
|
5
|
+
* @returns Correlation coefficient (-1 to 1)
|
|
6
|
+
* @example
|
|
7
|
+
* correlationCoefficient([1, 2, 3, 4, 5], [2, 4, 6, 8, 10]); // 1 (perfect positive correlation)
|
|
8
|
+
* correlationCoefficient([1, 2, 3, 4, 5], [5, 4, 3, 2, 1]); // -1 (perfect negative correlation)
|
|
9
|
+
* correlationCoefficient([1, 2, 3, 4, 5], [1, 1, 1, 1, 1]); // 0 (no correlation)
|
|
10
|
+
*/
|
|
11
|
+
export declare const correlationCoefficient: (x: number[], y: number[]) => number;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.correlationCoefficient = void 0;
|
|
7
|
+
var _average = require("./average");
|
|
8
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
9
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
10
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
11
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
12
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
13
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
14
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
15
|
+
/**
|
|
16
|
+
* Calculate the Pearson correlation coefficient between two arrays
|
|
17
|
+
* @param x - First array of numbers
|
|
18
|
+
* @param y - Second array of numbers
|
|
19
|
+
* @returns Correlation coefficient (-1 to 1)
|
|
20
|
+
* @example
|
|
21
|
+
* correlationCoefficient([1, 2, 3, 4, 5], [2, 4, 6, 8, 10]); // 1 (perfect positive correlation)
|
|
22
|
+
* correlationCoefficient([1, 2, 3, 4, 5], [5, 4, 3, 2, 1]); // -1 (perfect negative correlation)
|
|
23
|
+
* correlationCoefficient([1, 2, 3, 4, 5], [1, 1, 1, 1, 1]); // 0 (no correlation)
|
|
24
|
+
*/
|
|
25
|
+
var correlationCoefficient = exports.correlationCoefficient = function correlationCoefficient(x, y) {
|
|
26
|
+
if (x.length !== y.length) {
|
|
27
|
+
throw new Error("Arrays must have the same length");
|
|
28
|
+
}
|
|
29
|
+
if (x.length === 0) {
|
|
30
|
+
return Number.NaN;
|
|
31
|
+
}
|
|
32
|
+
if (x.length === 1) {
|
|
33
|
+
return Number.NaN;
|
|
34
|
+
}
|
|
35
|
+
var meanX = (0, _average.average)(x);
|
|
36
|
+
var meanY = (0, _average.average)(y);
|
|
37
|
+
var numerator = 0;
|
|
38
|
+
var sumSquaredX = 0;
|
|
39
|
+
var sumSquaredY = 0;
|
|
40
|
+
var _iterator = _createForOfIteratorHelper(x.entries()),
|
|
41
|
+
_step;
|
|
42
|
+
try {
|
|
43
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
44
|
+
var _step$value = _slicedToArray(_step.value, 2),
|
|
45
|
+
index = _step$value[0],
|
|
46
|
+
element = _step$value[1];
|
|
47
|
+
var deltaX = element - meanX;
|
|
48
|
+
var deltaY = y[index] - meanY;
|
|
49
|
+
numerator += deltaX * deltaY;
|
|
50
|
+
sumSquaredX += deltaX * deltaX;
|
|
51
|
+
sumSquaredY += deltaY * deltaY;
|
|
52
|
+
}
|
|
53
|
+
} catch (err) {
|
|
54
|
+
_iterator.e(err);
|
|
55
|
+
} finally {
|
|
56
|
+
_iterator.f();
|
|
57
|
+
}
|
|
58
|
+
var denominator = Math.sqrt(sumSquaredX * sumSquaredY);
|
|
59
|
+
if (denominator === 0) {
|
|
60
|
+
return Number.NaN;
|
|
61
|
+
}
|
|
62
|
+
return numerator / denominator;
|
|
63
|
+
};
|
|
@@ -2,6 +2,7 @@ export * from "./addition";
|
|
|
2
2
|
export * from "./average";
|
|
3
3
|
export * from "./bitwise";
|
|
4
4
|
export * from "./calculator";
|
|
5
|
+
export * from "./correlationCoefficient";
|
|
5
6
|
export * from "./degToRad";
|
|
6
7
|
export * from "./deviationValue";
|
|
7
8
|
export * from "./division";
|
|
@@ -17,11 +18,13 @@ export * from "./mathSeparator";
|
|
|
17
18
|
export * from "./max";
|
|
18
19
|
export * from "./median";
|
|
19
20
|
export * from "./min";
|
|
21
|
+
export * from "./mode";
|
|
20
22
|
export * from "./multiples";
|
|
21
23
|
export * from "./multiplication";
|
|
22
24
|
export * from "./nCr";
|
|
23
25
|
export * from "./nHr";
|
|
24
26
|
export * from "./nPr";
|
|
27
|
+
export * from "./percentile";
|
|
25
28
|
export * from "./primeFactorization";
|
|
26
29
|
export * from "./quotient";
|
|
27
30
|
export * from "./radToDeg";
|
package/module/es5/Math/index.js
CHANGED
|
@@ -47,6 +47,17 @@ Object.keys(_calculator).forEach(function (key) {
|
|
|
47
47
|
}
|
|
48
48
|
});
|
|
49
49
|
});
|
|
50
|
+
var _correlationCoefficient = require("./correlationCoefficient");
|
|
51
|
+
Object.keys(_correlationCoefficient).forEach(function (key) {
|
|
52
|
+
if (key === "default" || key === "__esModule") return;
|
|
53
|
+
if (key in exports && exports[key] === _correlationCoefficient[key]) return;
|
|
54
|
+
Object.defineProperty(exports, key, {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function get() {
|
|
57
|
+
return _correlationCoefficient[key];
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
50
61
|
var _degToRad = require("./degToRad");
|
|
51
62
|
Object.keys(_degToRad).forEach(function (key) {
|
|
52
63
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -212,6 +223,17 @@ Object.keys(_min).forEach(function (key) {
|
|
|
212
223
|
}
|
|
213
224
|
});
|
|
214
225
|
});
|
|
226
|
+
var _mode = require("./mode");
|
|
227
|
+
Object.keys(_mode).forEach(function (key) {
|
|
228
|
+
if (key === "default" || key === "__esModule") return;
|
|
229
|
+
if (key in exports && exports[key] === _mode[key]) return;
|
|
230
|
+
Object.defineProperty(exports, key, {
|
|
231
|
+
enumerable: true,
|
|
232
|
+
get: function get() {
|
|
233
|
+
return _mode[key];
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
});
|
|
215
237
|
var _multiples = require("./multiples");
|
|
216
238
|
Object.keys(_multiples).forEach(function (key) {
|
|
217
239
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -267,6 +289,17 @@ Object.keys(_nPr).forEach(function (key) {
|
|
|
267
289
|
}
|
|
268
290
|
});
|
|
269
291
|
});
|
|
292
|
+
var _percentile = require("./percentile");
|
|
293
|
+
Object.keys(_percentile).forEach(function (key) {
|
|
294
|
+
if (key === "default" || key === "__esModule") return;
|
|
295
|
+
if (key in exports && exports[key] === _percentile[key]) return;
|
|
296
|
+
Object.defineProperty(exports, key, {
|
|
297
|
+
enumerable: true,
|
|
298
|
+
get: function get() {
|
|
299
|
+
return _percentile[key];
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
});
|
|
270
303
|
var _primeFactorization = require("./primeFactorization");
|
|
271
304
|
Object.keys(_primeFactorization).forEach(function (key) {
|
|
272
305
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Finds the most frequently occurring value(s) in an array
|
|
3
|
+
* @param array - Array of numbers to find mode for
|
|
4
|
+
* @returns Array of mode values (can be multiple values if there are ties)
|
|
5
|
+
* @example
|
|
6
|
+
* mode([1, 2, 2, 3, 3, 3]); // [3]
|
|
7
|
+
* mode([1, 2, 2, 3, 3]); // [2, 3]
|
|
8
|
+
* mode([1, 2, 3]); // [1, 2, 3]
|
|
9
|
+
*/
|
|
10
|
+
export declare const mode: (array: number[]) => number[];
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.mode = void 0;
|
|
7
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
8
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
9
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
10
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
11
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
12
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
13
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
14
|
+
/**
|
|
15
|
+
* Finds the most frequently occurring value(s) in an array
|
|
16
|
+
* @param array - Array of numbers to find mode for
|
|
17
|
+
* @returns Array of mode values (can be multiple values if there are ties)
|
|
18
|
+
* @example
|
|
19
|
+
* mode([1, 2, 2, 3, 3, 3]); // [3]
|
|
20
|
+
* mode([1, 2, 2, 3, 3]); // [2, 3]
|
|
21
|
+
* mode([1, 2, 3]); // [1, 2, 3]
|
|
22
|
+
*/
|
|
23
|
+
var mode = exports.mode = function mode(array) {
|
|
24
|
+
if (array.length === 0) {
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
var frequency = new Map();
|
|
28
|
+
var maxFrequency = 0;
|
|
29
|
+
|
|
30
|
+
// Count frequencies
|
|
31
|
+
var _iterator = _createForOfIteratorHelper(array),
|
|
32
|
+
_step;
|
|
33
|
+
try {
|
|
34
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
35
|
+
var value = _step.value;
|
|
36
|
+
var count = (frequency.get(value) || 0) + 1;
|
|
37
|
+
frequency.set(value, count);
|
|
38
|
+
maxFrequency = Math.max(maxFrequency, count);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Find all values with maximum frequency
|
|
42
|
+
} catch (err) {
|
|
43
|
+
_iterator.e(err);
|
|
44
|
+
} finally {
|
|
45
|
+
_iterator.f();
|
|
46
|
+
}
|
|
47
|
+
var modes = [];
|
|
48
|
+
var _iterator2 = _createForOfIteratorHelper(frequency),
|
|
49
|
+
_step2;
|
|
50
|
+
try {
|
|
51
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
52
|
+
var _step2$value = _slicedToArray(_step2.value, 2),
|
|
53
|
+
_value = _step2$value[0],
|
|
54
|
+
_count = _step2$value[1];
|
|
55
|
+
if (_count === maxFrequency) {
|
|
56
|
+
modes.push(_value);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
} catch (err) {
|
|
60
|
+
_iterator2.e(err);
|
|
61
|
+
} finally {
|
|
62
|
+
_iterator2.f();
|
|
63
|
+
}
|
|
64
|
+
return modes.sort(function (a, b) {
|
|
65
|
+
return a - b;
|
|
66
|
+
});
|
|
67
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculate the nth percentile of values in an array
|
|
3
|
+
* @param array - Array of numbers
|
|
4
|
+
* @param percentile - Percentile value (0-100)
|
|
5
|
+
* @returns The percentile value
|
|
6
|
+
* @example
|
|
7
|
+
* percentile([1, 2, 3, 4, 5], 50); // 3 (50th percentile - median)
|
|
8
|
+
* percentile([1, 2, 3, 4, 5], 25); // 2 (25th percentile)
|
|
9
|
+
* percentile([1, 2, 3, 4, 5], 75); // 4 (75th percentile)
|
|
10
|
+
*/
|
|
11
|
+
export declare const percentile: (array: number[], percentile: number) => number;
|