data-structure-typed 1.52.4 → 1.52.5
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/CHANGELOG.md +1 -1
- package/README.md +13 -13
- package/README_zh-CN.md +216 -26
- package/benchmark/report.html +13 -13
- package/benchmark/report.json +158 -158
- package/dist/cjs/data-structures/base/iterable-element-base.d.ts +1 -37
- package/dist/cjs/data-structures/base/iterable-element-base.js +1 -37
- package/dist/cjs/data-structures/base/iterable-element-base.js.map +1 -1
- package/dist/cjs/data-structures/base/iterable-entry-base.d.ts +2 -54
- package/dist/cjs/data-structures/base/iterable-entry-base.js +1 -49
- package/dist/cjs/data-structures/base/iterable-entry-base.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -32
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +9 -41
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +0 -46
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +0 -46
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +82 -147
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +299 -331
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +1 -40
- package/dist/cjs/data-structures/binary-tree/bst.js +12 -44
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +0 -48
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +2 -50
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +0 -32
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +9 -41
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +0 -75
- package/dist/cjs/data-structures/graph/abstract-graph.js +0 -75
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +0 -98
- package/dist/cjs/data-structures/graph/directed-graph.js +0 -98
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +0 -50
- package/dist/cjs/data-structures/graph/undirected-graph.js +0 -50
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-map.d.ts +5 -92
- package/dist/cjs/data-structures/hash/hash-map.js +27 -111
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.d.ts +0 -32
- package/dist/cjs/data-structures/heap/heap.js +0 -32
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +5 -88
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +5 -88
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +1 -83
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +2 -84
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +1 -35
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js +1 -35
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +1 -98
- package/dist/cjs/data-structures/queue/deque.js +3 -99
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +1 -54
- package/dist/cjs/data-structures/queue/queue.js +0 -53
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/data-structures/stack/stack.d.ts +1 -34
- package/dist/cjs/data-structures/stack/stack.js +1 -34
- package/dist/cjs/data-structures/stack/stack.js.map +1 -1
- package/dist/cjs/data-structures/tree/tree.js +0 -1
- package/dist/cjs/data-structures/tree/tree.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.d.ts +0 -64
- package/dist/cjs/data-structures/trie/trie.js +0 -64
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +8 -0
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.js +6 -0
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/types/utils/utils.d.ts +13 -12
- package/dist/cjs/utils/number.d.ts +13 -0
- package/dist/cjs/utils/number.js +13 -0
- package/dist/cjs/utils/number.js.map +1 -1
- package/dist/cjs/utils/utils.d.ts +125 -3
- package/dist/cjs/utils/utils.js +177 -21
- package/dist/cjs/utils/utils.js.map +1 -1
- package/dist/mjs/data-structures/base/iterable-element-base.d.ts +1 -37
- package/dist/mjs/data-structures/base/iterable-element-base.js +1 -37
- package/dist/mjs/data-structures/base/iterable-entry-base.d.ts +2 -54
- package/dist/mjs/data-structures/base/iterable-entry-base.js +1 -49
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -32
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js +9 -41
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +0 -46
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +0 -46
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +82 -147
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +298 -332
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +1 -40
- package/dist/mjs/data-structures/binary-tree/bst.js +12 -44
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +0 -48
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +2 -50
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +0 -32
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +9 -41
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +0 -75
- package/dist/mjs/data-structures/graph/abstract-graph.js +0 -75
- package/dist/mjs/data-structures/graph/directed-graph.d.ts +0 -98
- package/dist/mjs/data-structures/graph/directed-graph.js +0 -98
- package/dist/mjs/data-structures/graph/undirected-graph.d.ts +0 -50
- package/dist/mjs/data-structures/graph/undirected-graph.js +0 -50
- package/dist/mjs/data-structures/hash/hash-map.d.ts +5 -92
- package/dist/mjs/data-structures/hash/hash-map.js +27 -111
- package/dist/mjs/data-structures/heap/heap.d.ts +0 -32
- package/dist/mjs/data-structures/heap/heap.js +0 -32
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +5 -88
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +5 -88
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +1 -83
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +2 -84
- package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +1 -35
- package/dist/mjs/data-structures/linked-list/skip-linked-list.js +1 -35
- package/dist/mjs/data-structures/queue/deque.d.ts +1 -98
- package/dist/mjs/data-structures/queue/deque.js +3 -99
- package/dist/mjs/data-structures/queue/queue.d.ts +1 -54
- package/dist/mjs/data-structures/queue/queue.js +0 -53
- package/dist/mjs/data-structures/stack/stack.d.ts +1 -34
- package/dist/mjs/data-structures/stack/stack.js +1 -34
- package/dist/mjs/data-structures/tree/tree.js +0 -1
- package/dist/mjs/data-structures/trie/trie.d.ts +0 -64
- package/dist/mjs/data-structures/trie/trie.js +0 -64
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +8 -0
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.js +5 -1
- package/dist/mjs/types/utils/utils.d.ts +13 -12
- package/dist/mjs/utils/number.d.ts +13 -0
- package/dist/mjs/utils/number.js +13 -0
- package/dist/mjs/utils/utils.d.ts +125 -3
- package/dist/mjs/utils/utils.js +177 -21
- package/dist/umd/data-structure-typed.js +408 -1474
- package/dist/umd/data-structure-typed.min.js +5 -4
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +6 -6
- package/src/data-structures/base/iterable-element-base.ts +2 -42
- package/src/data-structures/base/iterable-entry-base.ts +3 -62
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +8 -48
- package/src/data-structures/binary-tree/avl-tree.ts +0 -57
- package/src/data-structures/binary-tree/binary-tree.ts +329 -358
- package/src/data-structures/binary-tree/bst.ts +11 -54
- package/src/data-structures/binary-tree/rb-tree.ts +2 -62
- package/src/data-structures/binary-tree/tree-multi-map.ts +8 -48
- package/src/data-structures/graph/abstract-graph.ts +0 -92
- package/src/data-structures/graph/directed-graph.ts +0 -122
- package/src/data-structures/graph/undirected-graph.ts +0 -62
- package/src/data-structures/hash/hash-map.ts +29 -133
- package/src/data-structures/heap/heap.ts +0 -40
- package/src/data-structures/linked-list/doubly-linked-list.ts +5 -112
- package/src/data-structures/linked-list/singly-linked-list.ts +2 -104
- package/src/data-structures/linked-list/skip-linked-list.ts +1 -44
- package/src/data-structures/queue/deque.ts +2 -125
- package/src/data-structures/queue/queue.ts +1 -68
- package/src/data-structures/stack/stack.ts +1 -43
- package/src/data-structures/tree/tree.ts +1 -1
- package/src/data-structures/trie/trie.ts +0 -80
- package/src/types/data-structures/binary-tree/binary-tree.ts +8 -1
- package/src/types/utils/utils.ts +17 -15
- package/src/utils/number.ts +13 -0
- package/src/utils/utils.ts +174 -18
- package/test/config.ts +8 -0
- package/test/integration/all-in-one.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +13 -13
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +18 -13
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +471 -64
- package/test/unit/data-structures/binary-tree/bst.test.ts +167 -23
- package/test/unit/data-structures/binary-tree/overall.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/rb-tree.test.ts +136 -13
- package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +18 -13
- package/test/unit/data-structures/graph/directed-graph.test.ts +46 -32
- package/test/unit/data-structures/graph/map-graph.test.ts +24 -2
- package/test/unit/data-structures/graph/undirected-graph.test.ts +24 -24
- package/test/unit/data-structures/hash/hash-map.test.ts +225 -35
- package/test/unit/data-structures/heap/heap.test.ts +47 -39
- package/test/unit/data-structures/heap/min-heap.test.ts +5 -5
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +34 -4
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +32 -0
- package/test/unit/data-structures/matrix/matrix.test.ts +35 -5
- package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +31 -0
- package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +18 -0
- package/test/unit/data-structures/priority-queue/priority-queue.test.ts +17 -0
- package/test/unit/data-structures/queue/deque.test.ts +288 -47
- package/test/unit/data-structures/queue/queue.test.ts +62 -37
- package/test/unit/data-structures/stack/stack.test.ts +30 -5
- package/test/unit/data-structures/tree/tree.test.ts +58 -0
- package/test/unit/data-structures/trie/trie.test.ts +46 -5
- package/test/unit/utils/utils.test.ts +169 -0
package/dist/cjs/utils/utils.js
CHANGED
|
@@ -11,6 +11,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.roundFixed = exports.calcMinUnitsRequired = exports.isWeakKey = exports.throwRangeError = exports.rangeCheck = exports.getMSB = exports.trampolineAsync = exports.trampoline = exports.toThunk = exports.isThunk = exports.THUNK_SYMBOL = exports.arrayRemove = exports.uuidV4 = void 0;
|
|
13
13
|
exports.isComparable = isComparable;
|
|
14
|
+
/**
|
|
15
|
+
* The function generates a random UUID (Universally Unique Identifier) in TypeScript.
|
|
16
|
+
* @returns A randomly generated UUID (Universally Unique Identifier) in the format
|
|
17
|
+
* 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' where each 'x' is replaced with a random hexadecimal
|
|
18
|
+
* character.
|
|
19
|
+
*/
|
|
14
20
|
const uuidV4 = function () {
|
|
15
21
|
return 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'.replace(/[x]/g, function (c) {
|
|
16
22
|
const r = (Math.random() * 16) | 0, v = c == 'x' ? r : (r & 0x3) | 0x8;
|
|
@@ -18,6 +24,15 @@ const uuidV4 = function () {
|
|
|
18
24
|
});
|
|
19
25
|
};
|
|
20
26
|
exports.uuidV4 = uuidV4;
|
|
27
|
+
/**
|
|
28
|
+
* The `arrayRemove` function removes elements from an array based on a specified predicate function
|
|
29
|
+
* and returns the removed elements.
|
|
30
|
+
* @param {T[]} array - An array of elements that you want to filter based on the provided predicate
|
|
31
|
+
* function.
|
|
32
|
+
* @param predicate - The `predicate` parameter is a function that takes three arguments:
|
|
33
|
+
* @returns The `arrayRemove` function returns an array containing the elements that satisfy the given
|
|
34
|
+
* `predicate` function.
|
|
35
|
+
*/
|
|
21
36
|
const arrayRemove = function (array, predicate) {
|
|
22
37
|
let i = -1, len = array ? array.length : 0;
|
|
23
38
|
const result = [];
|
|
@@ -33,16 +48,43 @@ const arrayRemove = function (array, predicate) {
|
|
|
33
48
|
};
|
|
34
49
|
exports.arrayRemove = arrayRemove;
|
|
35
50
|
exports.THUNK_SYMBOL = Symbol('thunk');
|
|
51
|
+
/**
|
|
52
|
+
* The function `isThunk` checks if a given value is a function with a specific symbol property.
|
|
53
|
+
* @param {any} fnOrValue - The `fnOrValue` parameter in the `isThunk` function can be either a
|
|
54
|
+
* function or a value that you want to check if it is a thunk. Thunks are functions that are wrapped
|
|
55
|
+
* around a value or computation for lazy evaluation. The function checks if the `fnOrValue` is
|
|
56
|
+
* @returns The function `isThunk` is checking if the input `fnOrValue` is a function and if it has a
|
|
57
|
+
* property `__THUNK__` equal to `THUNK_SYMBOL`. The return value will be `true` if both conditions are
|
|
58
|
+
* met, otherwise it will be `false`.
|
|
59
|
+
*/
|
|
36
60
|
const isThunk = (fnOrValue) => {
|
|
37
61
|
return typeof fnOrValue === 'function' && fnOrValue.__THUNK__ === exports.THUNK_SYMBOL;
|
|
38
62
|
};
|
|
39
63
|
exports.isThunk = isThunk;
|
|
64
|
+
/**
|
|
65
|
+
* The `toThunk` function in TypeScript converts a function into a thunk by wrapping it in a closure.
|
|
66
|
+
* @param {ToThunkFn} fn - `fn` is a function that will be converted into a thunk.
|
|
67
|
+
* @returns A thunk function is being returned. Thunk functions are functions that delay the evaluation
|
|
68
|
+
* of an expression or operation until it is explicitly called or invoked. In this case, the `toThunk`
|
|
69
|
+
* function takes a function `fn` as an argument and returns a thunk function that, when called, will
|
|
70
|
+
* execute the `fn` function provided as an argument.
|
|
71
|
+
*/
|
|
40
72
|
const toThunk = (fn) => {
|
|
41
73
|
const thunk = () => fn();
|
|
42
74
|
thunk.__THUNK__ = exports.THUNK_SYMBOL;
|
|
43
75
|
return thunk;
|
|
44
76
|
};
|
|
45
77
|
exports.toThunk = toThunk;
|
|
78
|
+
/**
|
|
79
|
+
* The `trampoline` function in TypeScript enables tail call optimization by using thunks to avoid
|
|
80
|
+
* stack overflow.
|
|
81
|
+
* @param {TrlFn} fn - The `fn` parameter in the `trampoline` function is a function that takes any
|
|
82
|
+
* number of arguments and returns a value.
|
|
83
|
+
* @returns The `trampoline` function returns an object with two properties:
|
|
84
|
+
* 1. A function that executes the provided function `fn` and continues to execute any thunks returned
|
|
85
|
+
* by `fn` until a non-thunk value is returned.
|
|
86
|
+
* 2. A `cont` property that is a function which creates a thunk for the provided function `fn`.
|
|
87
|
+
*/
|
|
46
88
|
const trampoline = (fn) => {
|
|
47
89
|
const cont = (...args) => (0, exports.toThunk)(() => fn(...args));
|
|
48
90
|
return Object.assign((...args) => {
|
|
@@ -54,6 +96,18 @@ const trampoline = (fn) => {
|
|
|
54
96
|
}, { cont });
|
|
55
97
|
};
|
|
56
98
|
exports.trampoline = trampoline;
|
|
99
|
+
/**
|
|
100
|
+
* The `trampolineAsync` function in TypeScript allows for asynchronous trampolining of a given
|
|
101
|
+
* function.
|
|
102
|
+
* @param {TrlAsyncFn} fn - The `fn` parameter in the `trampolineAsync` function is expected to be a
|
|
103
|
+
* function that returns a Promise. This function will be called recursively until a non-thunk value is
|
|
104
|
+
* returned.
|
|
105
|
+
* @returns The `trampolineAsync` function returns an object with two properties:
|
|
106
|
+
* 1. An async function that executes the provided `TrlAsyncFn` function and continues to execute any
|
|
107
|
+
* thunks returned by the function until a non-thunk value is returned.
|
|
108
|
+
* 2. A `cont` property that is a function which wraps the provided `TrlAsyncFn` function in a thunk
|
|
109
|
+
* and returns it.
|
|
110
|
+
*/
|
|
57
111
|
const trampolineAsync = (fn) => {
|
|
58
112
|
const cont = (...args) => (0, exports.toThunk)(() => fn(...args));
|
|
59
113
|
return Object.assign((...args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -65,6 +119,15 @@ const trampolineAsync = (fn) => {
|
|
|
65
119
|
}), { cont });
|
|
66
120
|
};
|
|
67
121
|
exports.trampolineAsync = trampolineAsync;
|
|
122
|
+
/**
|
|
123
|
+
* The function `getMSB` returns the most significant bit of a given number.
|
|
124
|
+
* @param {number} value - The `value` parameter is a number for which we want to find the position of
|
|
125
|
+
* the Most Significant Bit (MSB). The function `getMSB` takes this number as input and calculates the
|
|
126
|
+
* position of the MSB in its binary representation.
|
|
127
|
+
* @returns The function `getMSB` returns the most significant bit (MSB) of the input `value`. If the
|
|
128
|
+
* input value is less than or equal to 0, it returns 0. Otherwise, it calculates the position of the
|
|
129
|
+
* MSB using the `Math.clz32` function and bitwise left shifts 1 to that position.
|
|
130
|
+
*/
|
|
68
131
|
const getMSB = (value) => {
|
|
69
132
|
if (value <= 0) {
|
|
70
133
|
return 0;
|
|
@@ -72,50 +135,143 @@ const getMSB = (value) => {
|
|
|
72
135
|
return 1 << (31 - Math.clz32(value));
|
|
73
136
|
};
|
|
74
137
|
exports.getMSB = getMSB;
|
|
138
|
+
/**
|
|
139
|
+
* The `rangeCheck` function in TypeScript is used to validate if an index is within a specified range
|
|
140
|
+
* and throws a `RangeError` with a custom message if it is out of bounds.
|
|
141
|
+
* @param {number} index - The `index` parameter represents the value that you want to check if it
|
|
142
|
+
* falls within a specified range.
|
|
143
|
+
* @param {number} min - The `min` parameter represents the minimum value that the `index` should be
|
|
144
|
+
* compared against in the `rangeCheck` function.
|
|
145
|
+
* @param {number} max - The `max` parameter in the `rangeCheck` function represents the maximum value
|
|
146
|
+
* that the `index` parameter is allowed to have. If the `index` is greater than this `max` value, a
|
|
147
|
+
* `RangeError` will be thrown.
|
|
148
|
+
* @param [message=Index out of bounds.] - The `message` parameter is a string that represents the
|
|
149
|
+
* error message to be thrown if the index is out of bounds. By default, if no message is provided when
|
|
150
|
+
* calling the `rangeCheck` function, the message "Index out of bounds." will be used.
|
|
151
|
+
*/
|
|
75
152
|
const rangeCheck = (index, min, max, message = 'Index out of bounds.') => {
|
|
76
153
|
if (index < min || index > max)
|
|
77
154
|
throw new RangeError(message);
|
|
78
155
|
};
|
|
79
156
|
exports.rangeCheck = rangeCheck;
|
|
157
|
+
/**
|
|
158
|
+
* The function `throwRangeError` throws a RangeError with a custom message if called.
|
|
159
|
+
* @param [message=The value is off-limits.] - The `message` parameter is a string that represents the
|
|
160
|
+
* error message to be displayed when a `RangeError` is thrown. If no message is provided, the default
|
|
161
|
+
* message is 'The value is off-limits.'.
|
|
162
|
+
*/
|
|
80
163
|
const throwRangeError = (message = 'The value is off-limits.') => {
|
|
81
164
|
throw new RangeError(message);
|
|
82
165
|
};
|
|
83
166
|
exports.throwRangeError = throwRangeError;
|
|
167
|
+
/**
|
|
168
|
+
* The function `isWeakKey` checks if the input is an object or a function in TypeScript.
|
|
169
|
+
* @param {unknown} input - The `input` parameter in the `isWeakKey` function is of type `unknown`,
|
|
170
|
+
* which means it can be any type. The function checks if the `input` is an object (excluding `null`)
|
|
171
|
+
* or a function, and returns a boolean indicating whether the `input` is a weak
|
|
172
|
+
* @returns The function `isWeakKey` returns a boolean value indicating whether the input is an object
|
|
173
|
+
* or a function.
|
|
174
|
+
*/
|
|
84
175
|
const isWeakKey = (input) => {
|
|
85
176
|
const inputType = typeof input;
|
|
86
177
|
return (inputType === 'object' && input !== null) || inputType === 'function';
|
|
87
178
|
};
|
|
88
179
|
exports.isWeakKey = isWeakKey;
|
|
180
|
+
/**
|
|
181
|
+
* The function `calcMinUnitsRequired` calculates the minimum number of units required to accommodate a
|
|
182
|
+
* given total quantity based on a specified unit size.
|
|
183
|
+
* @param {number} totalQuantity - The `totalQuantity` parameter represents the total quantity of items
|
|
184
|
+
* that need to be processed or handled.
|
|
185
|
+
* @param {number} unitSize - The `unitSize` parameter represents the size of each unit or package. It
|
|
186
|
+
* is used in the `calcMinUnitsRequired` function to calculate the minimum number of units required to
|
|
187
|
+
* accommodate a total quantity of items.
|
|
188
|
+
*/
|
|
89
189
|
const calcMinUnitsRequired = (totalQuantity, unitSize) => Math.floor((totalQuantity + unitSize - 1) / unitSize);
|
|
90
190
|
exports.calcMinUnitsRequired = calcMinUnitsRequired;
|
|
191
|
+
/**
|
|
192
|
+
* The `roundFixed` function in TypeScript rounds a number to a specified number of decimal places.
|
|
193
|
+
* @param {number} num - The `num` parameter is a number that you want to round to a certain number of
|
|
194
|
+
* decimal places.
|
|
195
|
+
* @param {number} [digit=10] - The `digit` parameter in the `roundFixed` function specifies the number
|
|
196
|
+
* of decimal places to round the number to. By default, it is set to 10 if not provided explicitly.
|
|
197
|
+
* @returns The function `roundFixed` returns a number that is rounded to the specified number of
|
|
198
|
+
* decimal places (default is 10 decimal places).
|
|
199
|
+
*/
|
|
91
200
|
const roundFixed = (num, digit = 10) => {
|
|
92
201
|
const multiplier = Math.pow(10, digit);
|
|
93
202
|
return Math.round(num * multiplier) / multiplier;
|
|
94
203
|
};
|
|
95
204
|
exports.roundFixed = roundFixed;
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
205
|
+
/**
|
|
206
|
+
* The function `isPrimitiveComparable` checks if a value is a primitive type that can be compared.
|
|
207
|
+
* @param {unknown} value - The `value` parameter in the `isPrimitiveComparable` function is of type
|
|
208
|
+
* `unknown`, which means it can be any type. The function checks if the `value` is a primitive type
|
|
209
|
+
* that can be compared, such as number, bigint, string, or boolean.
|
|
210
|
+
* @returns The function `isPrimitiveComparable` returns a boolean value indicating whether the input
|
|
211
|
+
* `value` is a primitive value that can be compared using standard comparison operators (<, >, <=,
|
|
212
|
+
* >=).
|
|
213
|
+
*/
|
|
214
|
+
function isPrimitiveComparable(value) {
|
|
215
|
+
const valueType = typeof value;
|
|
216
|
+
if (valueType === 'number')
|
|
217
|
+
return !Number.isNaN(value);
|
|
218
|
+
return valueType === 'bigint' || valueType === 'string' || valueType === 'boolean';
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* The function `tryObjectToPrimitive` attempts to convert an object to a comparable primitive value by
|
|
222
|
+
* first checking the `valueOf` method and then the `toString` method.
|
|
223
|
+
* @param {object} obj - The `obj` parameter in the `tryObjectToPrimitive` function is an object that
|
|
224
|
+
* you want to convert to a primitive value. The function attempts to convert the object to a primitive
|
|
225
|
+
* value by first checking if the object has a `valueOf` method. If the `valueOf` method exists, it
|
|
226
|
+
* @returns The function `tryObjectToPrimitive` returns a value of type `ComparablePrimitive` if a
|
|
227
|
+
* primitive comparable value is found within the object, or a string value if the object has a custom
|
|
228
|
+
* `toString` method that does not return `'[object Object]'`. If neither condition is met, the
|
|
229
|
+
* function returns `null`.
|
|
230
|
+
*/
|
|
231
|
+
function tryObjectToPrimitive(obj) {
|
|
232
|
+
if (typeof obj.valueOf === 'function') {
|
|
233
|
+
const valueOfResult = obj.valueOf();
|
|
234
|
+
if (valueOfResult !== obj) {
|
|
235
|
+
if (isPrimitiveComparable(valueOfResult))
|
|
236
|
+
return valueOfResult;
|
|
237
|
+
if (typeof valueOfResult === 'object' && valueOfResult !== null)
|
|
238
|
+
return tryObjectToPrimitive(valueOfResult);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (typeof obj.toString === 'function') {
|
|
242
|
+
const stringResult = obj.toString();
|
|
243
|
+
if (stringResult !== '[object Object]')
|
|
244
|
+
return stringResult;
|
|
245
|
+
}
|
|
246
|
+
return null;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* The function `isComparable` in TypeScript checks if a value is comparable, handling primitive values
|
|
250
|
+
* and objects with optional force comparison.
|
|
251
|
+
* @param {unknown} value - The `value` parameter in the `isComparable` function represents the value
|
|
252
|
+
* that you want to check if it is comparable. It can be of any type (`unknown`), and the function will
|
|
253
|
+
* determine if it is comparable based on certain conditions.
|
|
254
|
+
* @param [isForceObjectComparable=false] - The `isForceObjectComparable` parameter in the
|
|
255
|
+
* `isComparable` function is a boolean flag that determines whether to treat non-primitive values as
|
|
256
|
+
* comparable objects. When set to `true`, it forces the function to consider non-primitive values as
|
|
257
|
+
* comparable objects, regardless of their type.
|
|
258
|
+
* @returns The function `isComparable` returns a boolean value indicating whether the `value` is
|
|
259
|
+
* considered comparable or not.
|
|
260
|
+
*/
|
|
261
|
+
function isComparable(value, isForceObjectComparable = false) {
|
|
262
|
+
if (value === null || value === undefined)
|
|
107
263
|
return false;
|
|
108
|
-
if (
|
|
264
|
+
if (isPrimitiveComparable(value))
|
|
265
|
+
return true;
|
|
266
|
+
if (typeof value !== 'object')
|
|
109
267
|
return false;
|
|
110
|
-
if (
|
|
111
|
-
return
|
|
112
|
-
if (
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
// if (typeof key.toString === 'function') return isComparable(key.toString()); // This will also keep recursing because every string type has a toString method.
|
|
268
|
+
if (value instanceof Date)
|
|
269
|
+
return !Number.isNaN(value.getTime());
|
|
270
|
+
if (isForceObjectComparable)
|
|
271
|
+
return true;
|
|
272
|
+
const comparableValue = tryObjectToPrimitive(value);
|
|
273
|
+
if (comparableValue === null || comparableValue === undefined)
|
|
117
274
|
return false;
|
|
118
|
-
|
|
119
|
-
return false;
|
|
275
|
+
return isPrimitiveComparable(comparableValue);
|
|
120
276
|
}
|
|
121
277
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/utils/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/utils/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;AA+QA,oCAUC;AAhRD;;;;;GAKG;AACI,MAAM,MAAM,GAAG;IACpB,OAAO,sCAAsC,CAAC,OAAO,CAAC,MAAM,EAAE,UAAU,CAAC;QACvE,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,EAChC,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;QACrC,OAAO,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACxB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AANW,QAAA,MAAM,UAMjB;AAEF;;;;;;;;GAQG;AACI,MAAM,WAAW,GAAG,UAAa,KAAU,EAAE,SAA0D;IAC5G,IAAI,CAAC,GAAG,CAAC,CAAC,EACR,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IACjC,MAAM,MAAM,GAAG,EAAE,CAAC;IAElB,OAAO,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC;QACjB,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACvB,IAAI,SAAS,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,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AqB,CAAC,eAAe,CAAC,CAAC;AAChD,CAAC"}
|
|
@@ -16,10 +16,6 @@ export declare abstract class IterableElementBase<E, R, C> {
|
|
|
16
16
|
* `_toElementFn`.
|
|
17
17
|
*/
|
|
18
18
|
get toElementFn(): ((rawElement: R) => E) | undefined;
|
|
19
|
-
/**
|
|
20
|
-
* Time Complexity: O(n)
|
|
21
|
-
* Space Complexity: O(1)
|
|
22
|
-
*/
|
|
23
19
|
/**
|
|
24
20
|
* Time Complexity: O(n)
|
|
25
21
|
* Space Complexity: O(1)
|
|
@@ -30,10 +26,6 @@ export declare abstract class IterableElementBase<E, R, C> {
|
|
|
30
26
|
* parameter is used to pass any number of arguments to the `_getIterator` method.
|
|
31
27
|
*/
|
|
32
28
|
[Symbol.iterator](...args: any[]): IterableIterator<E>;
|
|
33
|
-
/**
|
|
34
|
-
* Time Complexity: O(n)
|
|
35
|
-
* Space Complexity: O(n)
|
|
36
|
-
*/
|
|
37
29
|
/**
|
|
38
30
|
* Time Complexity: O(n)
|
|
39
31
|
* Space Complexity: O(n)
|
|
@@ -41,10 +33,6 @@ export declare abstract class IterableElementBase<E, R, C> {
|
|
|
41
33
|
* The function returns an iterator that yields all the values in the object.
|
|
42
34
|
*/
|
|
43
35
|
values(): IterableIterator<E>;
|
|
44
|
-
/**
|
|
45
|
-
* Time Complexity: O(n)
|
|
46
|
-
* Space Complexity: O(1)
|
|
47
|
-
*/
|
|
48
36
|
/**
|
|
49
37
|
* Time Complexity: O(n)
|
|
50
38
|
* Space Complexity: O(1)
|
|
@@ -60,14 +48,6 @@ export declare abstract class IterableElementBase<E, R, C> {
|
|
|
60
48
|
* the array satisfies the provided predicate function, and `false` otherwise.
|
|
61
49
|
*/
|
|
62
50
|
every(predicate: ElementCallback<E, R, boolean, C>, thisArg?: any): boolean;
|
|
63
|
-
/**
|
|
64
|
-
* Time Complexity: O(n)
|
|
65
|
-
* Space Complexity: O(1)
|
|
66
|
-
*/
|
|
67
|
-
/**
|
|
68
|
-
* Time Complexity: O(n)
|
|
69
|
-
* Space Complexity: O(1)
|
|
70
|
-
*/
|
|
71
51
|
/**
|
|
72
52
|
* Time Complexity: O(n)
|
|
73
53
|
* Space Complexity: O(1)
|
|
@@ -83,10 +63,6 @@ export declare abstract class IterableElementBase<E, R, C> {
|
|
|
83
63
|
* in the collection, and false otherwise.
|
|
84
64
|
*/
|
|
85
65
|
some(predicate: ElementCallback<E, R, boolean, C>, thisArg?: any): boolean;
|
|
86
|
-
/**
|
|
87
|
-
* Time Complexity: O(n)
|
|
88
|
-
* Space Complexity: O(1)
|
|
89
|
-
*/
|
|
90
66
|
/**
|
|
91
67
|
* Time Complexity: O(n)
|
|
92
68
|
* Space Complexity: O(1)
|
|
@@ -101,10 +77,6 @@ export declare abstract class IterableElementBase<E, R, C> {
|
|
|
101
77
|
* be passed as the `this` value to the `callbackfn` function. If `thisArg
|
|
102
78
|
*/
|
|
103
79
|
forEach(callbackfn: ElementCallback<E, R, void, C>, thisArg?: any): void;
|
|
104
|
-
/**
|
|
105
|
-
* Time Complexity: O(n)
|
|
106
|
-
* Space Complexity: O(1)
|
|
107
|
-
*/
|
|
108
80
|
/**
|
|
109
81
|
* Time Complexity: O(n)
|
|
110
82
|
* Space Complexity: O(1)
|
|
@@ -133,10 +105,6 @@ export declare abstract class IterableElementBase<E, R, C> {
|
|
|
133
105
|
* otherwise.
|
|
134
106
|
*/
|
|
135
107
|
has(element: E): boolean;
|
|
136
|
-
/**
|
|
137
|
-
* Time Complexity: O(n)
|
|
138
|
-
* Space Complexity: O(1)
|
|
139
|
-
*/
|
|
140
108
|
/**
|
|
141
109
|
* Time Complexity: O(n)
|
|
142
110
|
* Space Complexity: O(1)
|
|
@@ -151,17 +119,13 @@ export declare abstract class IterableElementBase<E, R, C> {
|
|
|
151
119
|
* all the elements in the array and applying the callback function to each element.
|
|
152
120
|
*/
|
|
153
121
|
reduce<U>(callbackfn: ReduceElementCallback<E, R, U, C>, initialValue: U): U;
|
|
154
|
-
/**
|
|
155
|
-
* Time Complexity: O(n)
|
|
156
|
-
* Space Complexity: O(n)
|
|
157
|
-
*/
|
|
158
122
|
/**
|
|
159
123
|
* Time Complexity: O(n)
|
|
160
124
|
* Space Complexity: O(n)
|
|
161
125
|
*
|
|
162
126
|
* The print function logs the elements of an array to the console.
|
|
163
127
|
*/
|
|
164
|
-
print():
|
|
128
|
+
print(): E[];
|
|
165
129
|
abstract isEmpty(): boolean;
|
|
166
130
|
abstract clear(): void;
|
|
167
131
|
abstract clone(): C;
|
|
@@ -24,10 +24,6 @@ export class IterableElementBase {
|
|
|
24
24
|
get toElementFn() {
|
|
25
25
|
return this._toElementFn;
|
|
26
26
|
}
|
|
27
|
-
/**
|
|
28
|
-
* Time Complexity: O(n)
|
|
29
|
-
* Space Complexity: O(1)
|
|
30
|
-
*/
|
|
31
27
|
/**
|
|
32
28
|
* Time Complexity: O(n)
|
|
33
29
|
* Space Complexity: O(1)
|
|
@@ -40,10 +36,6 @@ export class IterableElementBase {
|
|
|
40
36
|
*[Symbol.iterator](...args) {
|
|
41
37
|
yield* this._getIterator(...args);
|
|
42
38
|
}
|
|
43
|
-
/**
|
|
44
|
-
* Time Complexity: O(n)
|
|
45
|
-
* Space Complexity: O(n)
|
|
46
|
-
*/
|
|
47
39
|
/**
|
|
48
40
|
* Time Complexity: O(n)
|
|
49
41
|
* Space Complexity: O(n)
|
|
@@ -55,10 +47,6 @@ export class IterableElementBase {
|
|
|
55
47
|
yield item;
|
|
56
48
|
}
|
|
57
49
|
}
|
|
58
|
-
/**
|
|
59
|
-
* Time Complexity: O(n)
|
|
60
|
-
* Space Complexity: O(1)
|
|
61
|
-
*/
|
|
62
50
|
/**
|
|
63
51
|
* Time Complexity: O(n)
|
|
64
52
|
* Space Complexity: O(1)
|
|
@@ -82,14 +70,6 @@ export class IterableElementBase {
|
|
|
82
70
|
}
|
|
83
71
|
return true;
|
|
84
72
|
}
|
|
85
|
-
/**
|
|
86
|
-
* Time Complexity: O(n)
|
|
87
|
-
* Space Complexity: O(1)
|
|
88
|
-
*/
|
|
89
|
-
/**
|
|
90
|
-
* Time Complexity: O(n)
|
|
91
|
-
* Space Complexity: O(1)
|
|
92
|
-
*/
|
|
93
73
|
/**
|
|
94
74
|
* Time Complexity: O(n)
|
|
95
75
|
* Space Complexity: O(1)
|
|
@@ -113,10 +93,6 @@ export class IterableElementBase {
|
|
|
113
93
|
}
|
|
114
94
|
return false;
|
|
115
95
|
}
|
|
116
|
-
/**
|
|
117
|
-
* Time Complexity: O(n)
|
|
118
|
-
* Space Complexity: O(1)
|
|
119
|
-
*/
|
|
120
96
|
/**
|
|
121
97
|
* Time Complexity: O(n)
|
|
122
98
|
* Space Complexity: O(1)
|
|
@@ -136,10 +112,6 @@ export class IterableElementBase {
|
|
|
136
112
|
callbackfn.call(thisArg, item, index++, this);
|
|
137
113
|
}
|
|
138
114
|
}
|
|
139
|
-
/**
|
|
140
|
-
* Time Complexity: O(n)
|
|
141
|
-
* Space Complexity: O(1)
|
|
142
|
-
*/
|
|
143
115
|
/**
|
|
144
116
|
* Time Complexity: O(n)
|
|
145
117
|
* Space Complexity: O(1)
|
|
@@ -181,10 +153,6 @@ export class IterableElementBase {
|
|
|
181
153
|
}
|
|
182
154
|
return false;
|
|
183
155
|
}
|
|
184
|
-
/**
|
|
185
|
-
* Time Complexity: O(n)
|
|
186
|
-
* Space Complexity: O(1)
|
|
187
|
-
*/
|
|
188
156
|
/**
|
|
189
157
|
* Time Complexity: O(n)
|
|
190
158
|
* Space Complexity: O(1)
|
|
@@ -206,10 +174,6 @@ export class IterableElementBase {
|
|
|
206
174
|
}
|
|
207
175
|
return accumulator;
|
|
208
176
|
}
|
|
209
|
-
/**
|
|
210
|
-
* Time Complexity: O(n)
|
|
211
|
-
* Space Complexity: O(n)
|
|
212
|
-
*/
|
|
213
177
|
/**
|
|
214
178
|
* Time Complexity: O(n)
|
|
215
179
|
* Space Complexity: O(n)
|
|
@@ -217,6 +181,6 @@ export class IterableElementBase {
|
|
|
217
181
|
* The print function logs the elements of an array to the console.
|
|
218
182
|
*/
|
|
219
183
|
print() {
|
|
220
|
-
|
|
184
|
+
return [...this];
|
|
221
185
|
}
|
|
222
186
|
}
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import { EntryCallback, ReduceEntryCallback } from '../../types';
|
|
2
2
|
export declare abstract class IterableEntryBase<K = any, V = any> {
|
|
3
|
-
/**
|
|
4
|
-
* Time Complexity: O(n)
|
|
5
|
-
* Space Complexity: O(1)
|
|
6
|
-
*/
|
|
7
3
|
abstract get size(): number;
|
|
8
4
|
/**
|
|
9
5
|
* Time Complexity: O(n)
|
|
@@ -15,10 +11,6 @@ export declare abstract class IterableEntryBase<K = any, V = any> {
|
|
|
15
11
|
* parameter is used to pass any additional arguments to the `_getIterator` method.
|
|
16
12
|
*/
|
|
17
13
|
[Symbol.iterator](...args: any[]): IterableIterator<[K, V]>;
|
|
18
|
-
/**
|
|
19
|
-
* Time Complexity: O(n)
|
|
20
|
-
* Space Complexity: O(n)
|
|
21
|
-
*/
|
|
22
14
|
/**
|
|
23
15
|
* Time Complexity: O(n)
|
|
24
16
|
* Space Complexity: O(n)
|
|
@@ -27,10 +19,6 @@ export declare abstract class IterableEntryBase<K = any, V = any> {
|
|
|
27
19
|
* be undefined.
|
|
28
20
|
*/
|
|
29
21
|
entries(): IterableIterator<[K, V | undefined]>;
|
|
30
|
-
/**
|
|
31
|
-
* Time Complexity: O(n)
|
|
32
|
-
* Space Complexity: O(n)
|
|
33
|
-
*/
|
|
34
22
|
/**
|
|
35
23
|
* Time Complexity: O(n)
|
|
36
24
|
* Space Complexity: O(n)
|
|
@@ -38,10 +26,6 @@ export declare abstract class IterableEntryBase<K = any, V = any> {
|
|
|
38
26
|
* The function returns an iterator that yields the keys of a data structure.
|
|
39
27
|
*/
|
|
40
28
|
keys(): IterableIterator<K>;
|
|
41
|
-
/**
|
|
42
|
-
* Time Complexity: O(n)
|
|
43
|
-
* Space Complexity: O(n)
|
|
44
|
-
*/
|
|
45
29
|
/**
|
|
46
30
|
* Time Complexity: O(n)
|
|
47
31
|
* Space Complexity: O(n)
|
|
@@ -49,10 +33,6 @@ export declare abstract class IterableEntryBase<K = any, V = any> {
|
|
|
49
33
|
* The function returns an iterator that yields the values of a collection.
|
|
50
34
|
*/
|
|
51
35
|
values(): IterableIterator<V>;
|
|
52
|
-
/**
|
|
53
|
-
* Time Complexity: O(n)
|
|
54
|
-
* Space Complexity: O(1)
|
|
55
|
-
*/
|
|
56
36
|
/**
|
|
57
37
|
* Time Complexity: O(n)
|
|
58
38
|
* Space Complexity: O(1)
|
|
@@ -68,10 +48,6 @@ export declare abstract class IterableEntryBase<K = any, V = any> {
|
|
|
68
48
|
* the collection satisfies the provided predicate function, and `false` otherwise.
|
|
69
49
|
*/
|
|
70
50
|
every(predicate: EntryCallback<K, V, boolean>, thisArg?: any): boolean;
|
|
71
|
-
/**
|
|
72
|
-
* Time Complexity: O(n)
|
|
73
|
-
* Space Complexity: O(1)
|
|
74
|
-
*/
|
|
75
51
|
/**
|
|
76
52
|
* Time Complexity: O(n)
|
|
77
53
|
* Space Complexity: O(1)
|
|
@@ -88,14 +64,6 @@ export declare abstract class IterableEntryBase<K = any, V = any> {
|
|
|
88
64
|
* the collection, and false otherwise.
|
|
89
65
|
*/
|
|
90
66
|
some(predicate: EntryCallback<K, V, boolean>, thisArg?: any): boolean;
|
|
91
|
-
/**
|
|
92
|
-
* Time Complexity: O(n)
|
|
93
|
-
* Space Complexity: O(1)
|
|
94
|
-
*/
|
|
95
|
-
/**
|
|
96
|
-
* Time Complexity: O(n)
|
|
97
|
-
* Space Complexity: O(1)
|
|
98
|
-
*/
|
|
99
67
|
/**
|
|
100
68
|
* Time Complexity: O(n)
|
|
101
69
|
* Space Complexity: O(1)
|
|
@@ -110,10 +78,6 @@ export declare abstract class IterableEntryBase<K = any, V = any> {
|
|
|
110
78
|
* used as the `this` value when calling the callback function. If `thisArg` is not provided, `
|
|
111
79
|
*/
|
|
112
80
|
forEach(callbackfn: EntryCallback<K, V, void>, thisArg?: any): void;
|
|
113
|
-
/**
|
|
114
|
-
* Time Complexity: O(n)
|
|
115
|
-
* Space Complexity: O(1)
|
|
116
|
-
*/
|
|
117
81
|
/**
|
|
118
82
|
* Time Complexity: O(n)
|
|
119
83
|
* Space Complexity: O(1)
|
|
@@ -131,11 +95,7 @@ export declare abstract class IterableEntryBase<K = any, V = any> {
|
|
|
131
95
|
* the provided callback function. If no element satisfies the callback function, `undefined` is
|
|
132
96
|
* returned.
|
|
133
97
|
*/
|
|
134
|
-
find(callbackfn: EntryCallback<K, V,
|
|
135
|
-
/**
|
|
136
|
-
* Time Complexity: O(n)
|
|
137
|
-
* Space Complexity: O(1)
|
|
138
|
-
*/
|
|
98
|
+
find(callbackfn: EntryCallback<K, V, boolean>, thisArg?: any): [K, V] | undefined;
|
|
139
99
|
/**
|
|
140
100
|
* Time Complexity: O(n)
|
|
141
101
|
* Space Complexity: O(1)
|
|
@@ -147,10 +107,6 @@ export declare abstract class IterableEntryBase<K = any, V = any> {
|
|
|
147
107
|
* otherwise.
|
|
148
108
|
*/
|
|
149
109
|
has(key: K): boolean;
|
|
150
|
-
/**
|
|
151
|
-
* Time Complexity: O(n)
|
|
152
|
-
* Space Complexity: O(1)
|
|
153
|
-
*/
|
|
154
110
|
/**
|
|
155
111
|
* Time Complexity: O(n)
|
|
156
112
|
* Space Complexity: O(1)
|
|
@@ -161,10 +117,6 @@ export declare abstract class IterableEntryBase<K = any, V = any> {
|
|
|
161
117
|
* @returns a boolean value, either true or false.
|
|
162
118
|
*/
|
|
163
119
|
hasValue(value: V): boolean;
|
|
164
|
-
/**
|
|
165
|
-
* Time Complexity: O(n)
|
|
166
|
-
* Space Complexity: O(1)
|
|
167
|
-
*/
|
|
168
120
|
/**
|
|
169
121
|
* Time Complexity: O(n)
|
|
170
122
|
* Space Complexity: O(1)
|
|
@@ -193,17 +145,13 @@ export declare abstract class IterableEntryBase<K = any, V = any> {
|
|
|
193
145
|
* all the elements in the collection.
|
|
194
146
|
*/
|
|
195
147
|
reduce<U>(callbackfn: ReduceEntryCallback<K, V, U>, initialValue: U): U;
|
|
196
|
-
/**
|
|
197
|
-
* Time Complexity: O(n)
|
|
198
|
-
* Space Complexity: O(n)
|
|
199
|
-
*/
|
|
200
148
|
/**
|
|
201
149
|
* Time Complexity: O(n)
|
|
202
150
|
* Space Complexity: O(n)
|
|
203
151
|
*
|
|
204
152
|
* The print function logs the elements of an array to the console.
|
|
205
153
|
*/
|
|
206
|
-
print():
|
|
154
|
+
print(): [K, V][] | string;
|
|
207
155
|
abstract isEmpty(): boolean;
|
|
208
156
|
abstract clear(): void;
|
|
209
157
|
abstract clone(): any;
|