data-structure-typed 2.0.4 → 2.1.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.
Files changed (261) hide show
  1. package/CHANGELOG.md +3 -1
  2. package/COMMANDS.md +17 -0
  3. package/README.md +11 -11
  4. package/benchmark/report.html +13 -77
  5. package/benchmark/report.json +158 -190
  6. package/dist/cjs/data-structures/base/iterable-element-base.d.ts +186 -83
  7. package/dist/cjs/data-structures/base/iterable-element-base.js +149 -107
  8. package/dist/cjs/data-structures/base/iterable-element-base.js.map +1 -1
  9. package/dist/cjs/data-structures/base/iterable-entry-base.d.ts +95 -119
  10. package/dist/cjs/data-structures/base/iterable-entry-base.js +59 -116
  11. package/dist/cjs/data-structures/base/iterable-entry-base.js.map +1 -1
  12. package/dist/cjs/data-structures/base/linear-base.d.ts +250 -192
  13. package/dist/cjs/data-structures/base/linear-base.js +137 -274
  14. package/dist/cjs/data-structures/base/linear-base.js.map +1 -1
  15. package/dist/cjs/data-structures/binary-tree/avl-tree-counter.d.ts +126 -158
  16. package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js +171 -205
  17. package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js.map +1 -1
  18. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +100 -69
  19. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +135 -87
  20. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
  21. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +138 -149
  22. package/dist/cjs/data-structures/binary-tree/avl-tree.js +208 -195
  23. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  24. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +476 -632
  25. package/dist/cjs/data-structures/binary-tree/binary-tree.js +608 -875
  26. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  27. package/dist/cjs/data-structures/binary-tree/bst.d.ts +258 -306
  28. package/dist/cjs/data-structures/binary-tree/bst.js +505 -481
  29. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  30. package/dist/cjs/data-structures/binary-tree/red-black-tree.d.ts +107 -179
  31. package/dist/cjs/data-structures/binary-tree/red-black-tree.js +114 -209
  32. package/dist/cjs/data-structures/binary-tree/red-black-tree.js.map +1 -1
  33. package/dist/cjs/data-structures/binary-tree/tree-counter.d.ts +132 -154
  34. package/dist/cjs/data-structures/binary-tree/tree-counter.js +172 -203
  35. package/dist/cjs/data-structures/binary-tree/tree-counter.js.map +1 -1
  36. package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +72 -69
  37. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +105 -85
  38. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
  39. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +238 -233
  40. package/dist/cjs/data-structures/graph/abstract-graph.js +267 -237
  41. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  42. package/dist/cjs/data-structures/graph/directed-graph.d.ts +108 -224
  43. package/dist/cjs/data-structures/graph/directed-graph.js +146 -233
  44. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  45. package/dist/cjs/data-structures/graph/map-graph.d.ts +49 -55
  46. package/dist/cjs/data-structures/graph/map-graph.js +56 -59
  47. package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
  48. package/dist/cjs/data-structures/graph/undirected-graph.d.ts +103 -146
  49. package/dist/cjs/data-structures/graph/undirected-graph.js +129 -149
  50. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  51. package/dist/cjs/data-structures/hash/hash-map.d.ts +164 -338
  52. package/dist/cjs/data-structures/hash/hash-map.js +270 -457
  53. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  54. package/dist/cjs/data-structures/heap/heap.d.ts +214 -289
  55. package/dist/cjs/data-structures/heap/heap.js +340 -349
  56. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  57. package/dist/cjs/data-structures/heap/max-heap.d.ts +11 -47
  58. package/dist/cjs/data-structures/heap/max-heap.js +11 -66
  59. package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
  60. package/dist/cjs/data-structures/heap/min-heap.d.ts +12 -47
  61. package/dist/cjs/data-structures/heap/min-heap.js +11 -66
  62. package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
  63. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +231 -347
  64. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +368 -494
  65. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  66. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +261 -310
  67. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +447 -466
  68. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  69. package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +0 -107
  70. package/dist/cjs/data-structures/linked-list/skip-linked-list.js +0 -100
  71. package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
  72. package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +12 -56
  73. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +11 -78
  74. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  75. package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +11 -57
  76. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +10 -79
  77. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  78. package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +2 -61
  79. package/dist/cjs/data-structures/priority-queue/priority-queue.js +8 -83
  80. package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
  81. package/dist/cjs/data-structures/queue/deque.d.ts +227 -254
  82. package/dist/cjs/data-structures/queue/deque.js +309 -348
  83. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  84. package/dist/cjs/data-structures/queue/queue.d.ts +180 -201
  85. package/dist/cjs/data-structures/queue/queue.js +265 -248
  86. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  87. package/dist/cjs/data-structures/stack/stack.d.ts +124 -102
  88. package/dist/cjs/data-structures/stack/stack.js +181 -125
  89. package/dist/cjs/data-structures/stack/stack.js.map +1 -1
  90. package/dist/cjs/data-structures/trie/trie.d.ts +164 -165
  91. package/dist/cjs/data-structures/trie/trie.js +189 -172
  92. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  93. package/dist/cjs/interfaces/binary-tree.d.ts +56 -6
  94. package/dist/cjs/interfaces/graph.d.ts +16 -0
  95. package/dist/cjs/types/data-structures/base/base.d.ts +1 -1
  96. package/dist/cjs/types/data-structures/graph/abstract-graph.d.ts +4 -0
  97. package/dist/cjs/types/utils/utils.d.ts +6 -6
  98. package/dist/cjs/utils/utils.d.ts +110 -49
  99. package/dist/cjs/utils/utils.js +148 -73
  100. package/dist/cjs/utils/utils.js.map +1 -1
  101. package/dist/esm/data-structures/base/iterable-element-base.d.ts +186 -83
  102. package/dist/esm/data-structures/base/iterable-element-base.js +155 -107
  103. package/dist/esm/data-structures/base/iterable-element-base.js.map +1 -1
  104. package/dist/esm/data-structures/base/iterable-entry-base.d.ts +95 -119
  105. package/dist/esm/data-structures/base/iterable-entry-base.js +59 -116
  106. package/dist/esm/data-structures/base/iterable-entry-base.js.map +1 -1
  107. package/dist/esm/data-structures/base/linear-base.d.ts +250 -192
  108. package/dist/esm/data-structures/base/linear-base.js +137 -274
  109. package/dist/esm/data-structures/base/linear-base.js.map +1 -1
  110. package/dist/esm/data-structures/binary-tree/avl-tree-counter.d.ts +126 -158
  111. package/dist/esm/data-structures/binary-tree/avl-tree-counter.js +171 -212
  112. package/dist/esm/data-structures/binary-tree/avl-tree-counter.js.map +1 -1
  113. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.d.ts +100 -69
  114. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js +133 -94
  115. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
  116. package/dist/esm/data-structures/binary-tree/avl-tree.d.ts +138 -149
  117. package/dist/esm/data-structures/binary-tree/avl-tree.js +206 -200
  118. package/dist/esm/data-structures/binary-tree/avl-tree.js.map +1 -1
  119. package/dist/esm/data-structures/binary-tree/binary-tree.d.ts +476 -632
  120. package/dist/esm/data-structures/binary-tree/binary-tree.js +613 -885
  121. package/dist/esm/data-structures/binary-tree/binary-tree.js.map +1 -1
  122. package/dist/esm/data-structures/binary-tree/bst.d.ts +258 -306
  123. package/dist/esm/data-structures/binary-tree/bst.js +507 -487
  124. package/dist/esm/data-structures/binary-tree/bst.js.map +1 -1
  125. package/dist/esm/data-structures/binary-tree/red-black-tree.d.ts +107 -179
  126. package/dist/esm/data-structures/binary-tree/red-black-tree.js +114 -215
  127. package/dist/esm/data-structures/binary-tree/red-black-tree.js.map +1 -1
  128. package/dist/esm/data-structures/binary-tree/tree-counter.d.ts +132 -154
  129. package/dist/esm/data-structures/binary-tree/tree-counter.js +175 -209
  130. package/dist/esm/data-structures/binary-tree/tree-counter.js.map +1 -1
  131. package/dist/esm/data-structures/binary-tree/tree-multi-map.d.ts +72 -69
  132. package/dist/esm/data-structures/binary-tree/tree-multi-map.js +103 -92
  133. package/dist/esm/data-structures/binary-tree/tree-multi-map.js.map +1 -1
  134. package/dist/esm/data-structures/graph/abstract-graph.d.ts +238 -233
  135. package/dist/esm/data-structures/graph/abstract-graph.js +267 -237
  136. package/dist/esm/data-structures/graph/abstract-graph.js.map +1 -1
  137. package/dist/esm/data-structures/graph/directed-graph.d.ts +108 -224
  138. package/dist/esm/data-structures/graph/directed-graph.js +145 -233
  139. package/dist/esm/data-structures/graph/directed-graph.js.map +1 -1
  140. package/dist/esm/data-structures/graph/map-graph.d.ts +49 -55
  141. package/dist/esm/data-structures/graph/map-graph.js +56 -59
  142. package/dist/esm/data-structures/graph/map-graph.js.map +1 -1
  143. package/dist/esm/data-structures/graph/undirected-graph.d.ts +103 -146
  144. package/dist/esm/data-structures/graph/undirected-graph.js +128 -149
  145. package/dist/esm/data-structures/graph/undirected-graph.js.map +1 -1
  146. package/dist/esm/data-structures/hash/hash-map.d.ts +164 -338
  147. package/dist/esm/data-structures/hash/hash-map.js +270 -457
  148. package/dist/esm/data-structures/hash/hash-map.js.map +1 -1
  149. package/dist/esm/data-structures/heap/heap.d.ts +214 -289
  150. package/dist/esm/data-structures/heap/heap.js +329 -349
  151. package/dist/esm/data-structures/heap/heap.js.map +1 -1
  152. package/dist/esm/data-structures/heap/max-heap.d.ts +11 -47
  153. package/dist/esm/data-structures/heap/max-heap.js +11 -66
  154. package/dist/esm/data-structures/heap/max-heap.js.map +1 -1
  155. package/dist/esm/data-structures/heap/min-heap.d.ts +12 -47
  156. package/dist/esm/data-structures/heap/min-heap.js +11 -66
  157. package/dist/esm/data-structures/heap/min-heap.js.map +1 -1
  158. package/dist/esm/data-structures/linked-list/doubly-linked-list.d.ts +231 -347
  159. package/dist/esm/data-structures/linked-list/doubly-linked-list.js +368 -495
  160. package/dist/esm/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  161. package/dist/esm/data-structures/linked-list/singly-linked-list.d.ts +261 -310
  162. package/dist/esm/data-structures/linked-list/singly-linked-list.js +448 -467
  163. package/dist/esm/data-structures/linked-list/singly-linked-list.js.map +1 -1
  164. package/dist/esm/data-structures/linked-list/skip-linked-list.d.ts +0 -107
  165. package/dist/esm/data-structures/linked-list/skip-linked-list.js +0 -100
  166. package/dist/esm/data-structures/linked-list/skip-linked-list.js.map +1 -1
  167. package/dist/esm/data-structures/priority-queue/max-priority-queue.d.ts +12 -56
  168. package/dist/esm/data-structures/priority-queue/max-priority-queue.js +11 -78
  169. package/dist/esm/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  170. package/dist/esm/data-structures/priority-queue/min-priority-queue.d.ts +11 -57
  171. package/dist/esm/data-structures/priority-queue/min-priority-queue.js +10 -79
  172. package/dist/esm/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  173. package/dist/esm/data-structures/priority-queue/priority-queue.d.ts +2 -61
  174. package/dist/esm/data-structures/priority-queue/priority-queue.js +8 -83
  175. package/dist/esm/data-structures/priority-queue/priority-queue.js.map +1 -1
  176. package/dist/esm/data-structures/queue/deque.d.ts +227 -254
  177. package/dist/esm/data-structures/queue/deque.js +313 -348
  178. package/dist/esm/data-structures/queue/deque.js.map +1 -1
  179. package/dist/esm/data-structures/queue/queue.d.ts +180 -201
  180. package/dist/esm/data-structures/queue/queue.js +263 -248
  181. package/dist/esm/data-structures/queue/queue.js.map +1 -1
  182. package/dist/esm/data-structures/stack/stack.d.ts +124 -102
  183. package/dist/esm/data-structures/stack/stack.js +181 -125
  184. package/dist/esm/data-structures/stack/stack.js.map +1 -1
  185. package/dist/esm/data-structures/trie/trie.d.ts +164 -165
  186. package/dist/esm/data-structures/trie/trie.js +193 -172
  187. package/dist/esm/data-structures/trie/trie.js.map +1 -1
  188. package/dist/esm/interfaces/binary-tree.d.ts +56 -6
  189. package/dist/esm/interfaces/graph.d.ts +16 -0
  190. package/dist/esm/types/data-structures/base/base.d.ts +1 -1
  191. package/dist/esm/types/data-structures/graph/abstract-graph.d.ts +4 -0
  192. package/dist/esm/types/utils/utils.d.ts +6 -6
  193. package/dist/esm/utils/utils.d.ts +110 -49
  194. package/dist/esm/utils/utils.js +139 -68
  195. package/dist/esm/utils/utils.js.map +1 -1
  196. package/dist/umd/data-structure-typed.js +4737 -6525
  197. package/dist/umd/data-structure-typed.min.js +8 -6
  198. package/dist/umd/data-structure-typed.min.js.map +1 -1
  199. package/package.json +3 -4
  200. package/src/data-structures/base/iterable-element-base.ts +238 -115
  201. package/src/data-structures/base/iterable-entry-base.ts +96 -120
  202. package/src/data-structures/base/linear-base.ts +271 -277
  203. package/src/data-structures/binary-tree/avl-tree-counter.ts +198 -216
  204. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +192 -101
  205. package/src/data-structures/binary-tree/avl-tree.ts +239 -206
  206. package/src/data-structures/binary-tree/binary-tree.ts +677 -901
  207. package/src/data-structures/binary-tree/bst.ts +568 -570
  208. package/src/data-structures/binary-tree/red-black-tree.ts +161 -222
  209. package/src/data-structures/binary-tree/tree-counter.ts +199 -218
  210. package/src/data-structures/binary-tree/tree-multi-map.ts +131 -97
  211. package/src/data-structures/graph/abstract-graph.ts +339 -264
  212. package/src/data-structures/graph/directed-graph.ts +146 -236
  213. package/src/data-structures/graph/map-graph.ts +63 -60
  214. package/src/data-structures/graph/undirected-graph.ts +129 -152
  215. package/src/data-structures/hash/hash-map.ts +274 -496
  216. package/src/data-structures/heap/heap.ts +389 -402
  217. package/src/data-structures/heap/max-heap.ts +12 -76
  218. package/src/data-structures/heap/min-heap.ts +13 -76
  219. package/src/data-structures/linked-list/doubly-linked-list.ts +426 -530
  220. package/src/data-structures/linked-list/singly-linked-list.ts +495 -517
  221. package/src/data-structures/linked-list/skip-linked-list.ts +1 -108
  222. package/src/data-structures/priority-queue/max-priority-queue.ts +12 -87
  223. package/src/data-structures/priority-queue/min-priority-queue.ts +11 -88
  224. package/src/data-structures/priority-queue/priority-queue.ts +3 -92
  225. package/src/data-structures/queue/deque.ts +381 -357
  226. package/src/data-structures/queue/queue.ts +310 -264
  227. package/src/data-structures/stack/stack.ts +217 -131
  228. package/src/data-structures/trie/trie.ts +240 -175
  229. package/src/interfaces/binary-tree.ts +240 -6
  230. package/src/interfaces/graph.ts +37 -0
  231. package/src/types/data-structures/base/base.ts +5 -5
  232. package/src/types/data-structures/graph/abstract-graph.ts +5 -0
  233. package/src/types/utils/utils.ts +9 -5
  234. package/src/utils/utils.ts +152 -86
  235. package/test/integration/index.html +1 -1
  236. package/test/performance/benchmark-runner.ts +528 -0
  237. package/test/performance/reportor.mjs +43 -43
  238. package/test/performance/runner-config.json +39 -0
  239. package/test/performance/single-suite-runner.ts +69 -0
  240. package/test/unit/data-structures/binary-tree/avl-tree-counter.test.ts +3 -3
  241. package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +5 -5
  242. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +4 -4
  243. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +350 -90
  244. package/test/unit/data-structures/binary-tree/bst.test.ts +84 -5
  245. package/test/unit/data-structures/binary-tree/red-black-tree.test.ts +2 -2
  246. package/test/unit/data-structures/binary-tree/tree-counter.test.ts +25 -24
  247. package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +3 -3
  248. package/test/unit/data-structures/graph/abstract-graph.test.ts +0 -4
  249. package/test/unit/data-structures/graph/directed-graph.test.ts +1 -1
  250. package/test/unit/data-structures/heap/heap.test.ts +14 -21
  251. package/test/unit/data-structures/heap/max-heap.test.ts +5 -9
  252. package/test/unit/data-structures/heap/min-heap.test.ts +1 -4
  253. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +14 -14
  254. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +0 -7
  255. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +8 -11
  256. package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +1 -4
  257. package/test/unit/data-structures/priority-queue/priority-queue.test.ts +1 -4
  258. package/test/unit/data-structures/queue/queue.test.ts +4 -5
  259. package/test/unit/utils/utils.test.ts +0 -1
  260. package/test/performance/data-structures/binary-tree/avl-tree.test.mjs +0 -71
  261. package/test/performance/data-structures/binary-tree/red-black-tree.test.mjs +0 -81
@@ -1,31 +1,66 @@
1
1
  import { IterableElementBase } from './iterable-element-base';
2
+ /**
3
+ * Singly-linked list node.
4
+ * @template E - Element type.
5
+ * @remarks Time O(1), Space O(1)
6
+ */
2
7
  export class LinkedListNode {
8
+ /**
9
+ * Initialize a node.
10
+ * @param value - Element value.
11
+ * @remarks Time O(1), Space O(1)
12
+ */
3
13
  constructor(value) {
4
14
  this._value = value;
5
15
  this._next = undefined;
6
16
  }
7
17
  _value;
18
+ /**
19
+ * Element payload getter.
20
+ * @returns Element value.
21
+ * @remarks Time O(1), Space O(1)
22
+ */
8
23
  get value() {
9
24
  return this._value;
10
25
  }
26
+ /**
27
+ * Element payload setter.
28
+ * @param value - New value.
29
+ * @remarks Time O(1), Space O(1)
30
+ */
11
31
  set value(value) {
12
32
  this._value = value;
13
33
  }
14
34
  _next;
35
+ /**
36
+ * Next node getter.
37
+ * @returns Next node or `undefined`.
38
+ * @remarks Time O(1), Space O(1)
39
+ */
15
40
  get next() {
16
41
  return this._next;
17
42
  }
43
+ /**
44
+ * Next node setter.
45
+ * @param value - Next node or `undefined`.
46
+ * @remarks Time O(1), Space O(1)
47
+ */
18
48
  set next(value) {
19
49
  this._next = value;
20
50
  }
21
51
  }
52
+ /**
53
+ * Abstract linear container with array-like utilities.
54
+ * @template E - Element type.
55
+ * @template R - Return type for mapped/derived views.
56
+ * @template NODE - Linked node type used by some implementations.
57
+ * @remarks Time O(1), Space O(1)
58
+ */
22
59
  export class LinearBase extends IterableElementBase {
23
60
  /**
24
- * The constructor initializes the LinearBase class with optional options, setting the maximum length
25
- * if provided.
26
- * @param [options] - The `options` parameter is an optional object that can be passed to the
27
- * constructor. It is of type `LinearBaseOptions<E, R>`. The constructor checks if the `options`
28
- * object is provided and then extracts the `maxLen` property from it. If `maxLen` is a
61
+ * Construct a linear container with runtime options.
62
+ * @param options - `{ maxLen?, ... }` bounds/behavior options.
63
+ * @remarks Time O(1), Space O(1)
29
64
  */
30
65
  constructor(options) {
31
66
  super(options);
@@ -36,58 +71,41 @@ export class LinearBase extends IterableElementBase {
36
71
  }
37
72
  }
38
73
  _maxLen = -1;
74
+ /**
75
+ * Upper bound for length (if positive), or `-1` when unbounded.
76
+ * @returns Maximum allowed length.
77
+ * @remarks Time O(1), Space O(1)
78
+ */
39
79
  get maxLen() {
40
80
  return this._maxLen;
41
81
  }
42
82
  /**
43
- * Time Complexity: O(n)
44
- * Space Complexity: O(1)
45
- *
46
- * The function indexOf searches for a specified element starting from a given index in an array-like
47
- * object and returns the index of the first occurrence, or -1 if not found.
48
- * @param {E} searchElement - The `searchElement` parameter in the `indexOf` function represents the
49
- * element that you want to find within the array. The function will search for this element starting
50
- * from the `fromIndex` (if provided) up to the end of the array. If the `searchElement` is found
51
- * within the
52
- * @param {number} [fromIndex=0] - The `fromIndex` parameter in the `indexOf` function represents the
53
- * index at which to start searching for the `searchElement` within the array. If provided, the
54
- * search will begin at this index and continue to the end of the array. If `fromIndex` is not
55
- * specified, the default
56
- * @returns The `indexOf` method is returning the index of the `searchElement` if it is found in the
57
- * array starting from the `fromIndex`. If the `searchElement` is not found, it returns -1.
83
+ * First index of a value from the left.
84
+ * @param searchElement - Value to match.
85
+ * @param fromIndex - Start position (supports negative index).
86
+ * @returns Index or `-1` if not found.
87
+ * @remarks Time O(n), Space O(1)
58
88
  */
59
89
  indexOf(searchElement, fromIndex = 0) {
60
- // Boundary checks and adjustments
61
90
  if (this.length === 0)
62
91
  return -1;
63
92
  if (fromIndex < 0)
64
93
  fromIndex = this.length + fromIndex;
65
94
  if (fromIndex < 0)
66
95
  fromIndex = 0;
67
- // Iterating from the specified index to the end
68
96
  for (let i = fromIndex; i < this.length; i++) {
69
97
  const element = this.at(i);
70
98
  if (element === searchElement)
71
99
  return i;
72
100
  }
73
- return -1; // Not found
101
+ return -1;
74
102
  }
75
103
  /**
76
- * Time Complexity: O(n)
77
- * Space Complexity: O(1)
78
- *
79
- * The function `lastIndexOf` in TypeScript returns the index of the last occurrence of a specified
80
- * element in an array.
81
- * @param {E} searchElement - The `searchElement` parameter is the element that you want to find the
82
- * last index of within the array. The `lastIndexOf` method will search the array starting from the
83
- * `fromIndex` (or the end of the array if not specified) and return the index of the last occurrence
84
- * of the
85
- * @param {number} fromIndex - The `fromIndex` parameter in the `lastIndexOf` method specifies the
86
- * index at which to start searching for the `searchElement` in the array. By default, it starts
87
- * searching from the last element of the array (`this.length - 1`). If a specific `fromIndex` is
88
- * provided
89
- * @returns The last index of the `searchElement` in the array is being returned. If the
90
- * `searchElement` is not found in the array, -1 is returned.
104
+ * Last index of a value from the right.
105
+ * @param searchElement - Value to match.
106
+ * @param fromIndex - Start position (supports negative index).
107
+ * @returns Index or `-1` if not found.
108
+ * @remarks Time O(n), Space O(1)
91
109
  */
92
110
  lastIndexOf(searchElement, fromIndex = this.length - 1) {
93
111
  if (this.length === 0)
@@ -104,19 +122,11 @@ export class LinearBase extends IterableElementBase {
104
122
  return -1;
105
123
  }
106
124
  /**
107
- * Time Complexity: O(n)
108
- * Space Complexity: O(1)
109
- *
110
- * The `findIndex` function iterates over an array and returns the index of the first element that
111
- * satisfies the provided predicate function.
112
- * @param predicate - The `predicate` parameter in the `findIndex` function is a callback function
113
- * that takes three arguments: `item`, `index`, and the array `this`. It should return a boolean
114
- * value indicating whether the current element satisfies the condition being checked for.
115
- * @param {any} [thisArg] - The `thisArg` parameter in the `findIndex` function is an optional
116
- * parameter that specifies the value to use as `this` when executing the `predicate` function. If
117
- * provided, the `predicate` function will be called with `thisArg` as its `this` value. If `
118
- * @returns The `findIndex` method is returning the index of the first element in the array that
119
- * satisfies the provided predicate function. If no such element is found, it returns -1.
125
+ * Find the first index matching a predicate.
126
+ * @param predicate - `(element, index, self) => boolean`.
127
+ * @param thisArg - Optional `this` for callback.
128
+ * @returns Index or `-1`.
129
+ * @remarks Time O(n), Space O(1)
120
130
  */
121
131
  findIndex(predicate, thisArg) {
122
132
  for (let i = 0; i < this.length; i++) {
@@ -127,15 +137,10 @@ export class LinearBase extends IterableElementBase {
127
137
  return -1;
128
138
  }
129
139
  /**
130
- * Time Complexity: O(n + m)
131
- * Space Complexity: O(n + m)
132
- *
133
- * The `concat` function in TypeScript concatenates multiple items into a new list, handling both
134
- * individual elements and instances of `LinearBase`.
135
- * @param {(E | this)[]} items - The `concat` method takes in an array of items, where
136
- * each item can be either of type `E` or an instance of `LinearBase<E, R>`.
137
- * @returns The `concat` method is returning a new instance of the class that it belongs to, with the
138
- * items passed as arguments concatenated to it.
140
+ * Concatenate elements and/or containers.
141
+ * @param items - Elements or other containers.
142
+ * @returns New container with combined elements (`this` type).
143
+ * @remarks Time O(sum(length)), Space O(sum(length))
139
144
  */
140
145
  concat(...items) {
141
146
  const newList = this.clone();
@@ -150,16 +155,10 @@ export class LinearBase extends IterableElementBase {
150
155
  return newList;
151
156
  }
152
157
  /**
153
- * Time Complexity: O(n log n)
154
- * Space Complexity: O(n)
155
- *
156
- * The `sort` function in TypeScript sorts the elements of a collection using a specified comparison
157
- * function.
158
- * @param [compareFn] - The `compareFn` parameter is a function that defines the sort order. It takes
159
- * two elements `a` and `b` as input and returns a number indicating their relative order. If the
160
- * returned value is negative, `a` comes before `b`. If the returned value is positive, `
161
- * @returns The `sort` method is returning the instance of the object on which it is called (this),
162
- * after sorting the elements based on the provided comparison function (compareFn).
158
+ * In-place stable order via array sort semantics.
159
+ * @param compareFn - Comparator `(a, b) => number`.
160
+ * @returns This container.
161
+ * @remarks Time O(n log n), Space O(n) (materializes to array temporarily)
163
162
  */
164
163
  sort(compareFn) {
165
164
  const arr = this.toArray();
@@ -170,69 +169,42 @@ export class LinearBase extends IterableElementBase {
170
169
  return this;
171
170
  }
172
171
  /**
173
- * Time Complexity: O(n + m)
174
- * Space Complexity: O(m)
175
- *
176
- * The `splice` function in TypeScript removes elements from an array and optionally inserts new
177
- * elements at the specified index.
178
- * @param {number} start - The `start` parameter in the `splice` method indicates the index at which
179
- * to start modifying the array. If `start` is a negative number, it will count from the end of the
180
- * array.
181
- * @param {number} [deleteCount=0] - The `deleteCount` parameter in the `splice` method specifies the
182
- * number of elements to remove from the array starting at the specified `start` index. If
183
- * `deleteCount` is not provided or is 0, no elements are removed, and only new elements are inserted
184
- * at the `start`
185
- * @param {E[]} items - The `items` parameter in the `splice` method represents the elements that
186
- * will be inserted into the array at the specified `start` index. These elements can be of any type
187
- * and you can pass multiple elements separated by commas. The `splice` method will insert these
188
- * items into the array at the
189
- * @returns The `splice` method returns a list of elements that were removed from the original list
190
- * during the operation.
172
+ * Remove and/or insert elements at a position (array-compatible).
173
+ * @param start - Start index (supports negative index).
174
+ * @param deleteCount - How many to remove.
175
+ * @param items - Elements to insert.
176
+ * @returns Removed elements as a new list (`this` type).
177
+ * @remarks Time O(n + m), Space O(min(n, m)) where `m = items.length`
191
178
  */
192
179
  splice(start, deleteCount = 0, ...items) {
193
180
  const removedList = this._createInstance();
194
- // Handling negative indexes and bounds
195
181
  start = start < 0 ? this.length + start : start;
196
182
  start = Math.max(0, Math.min(start, this.length));
197
183
  deleteCount = Math.max(0, Math.min(deleteCount, this.length - start));
198
- // Delete elements
199
184
  for (let i = 0; i < deleteCount; i++) {
200
- const removed = this.deleteAt(start); // Always delete the start position
185
+ const removed = this.deleteAt(start);
201
186
  if (removed !== undefined) {
202
- removedList.push(removed); // Add removed elements to the returned list
187
+ removedList.push(removed);
203
188
  }
204
189
  }
205
- // Insert new element
206
190
  for (let i = 0; i < items.length; i++) {
207
- this.addAt(start + i, items[i]); // Insert new elements one by one at the current position
191
+ this.addAt(start + i, items[i]);
208
192
  }
209
- return removedList; // Returns a list of removed elements
193
+ return removedList;
210
194
  }
211
195
  /**
212
- * Time Complexity: O(n)
213
- * Space Complexity: O(1)
214
- *
215
- * The `join` function in TypeScript returns a string by joining the elements of an array with a
216
- * specified separator.
217
- * @param {string} [separator=,] - The `separator` parameter is a string that specifies the character
218
- * or characters that will be used to separate each element when joining them into a single string.
219
- * By default, the separator is set to a comma (`,`), but you can provide a different separator if
220
- * needed.
221
- * @returns The `join` method is being returned, which takes an optional `separator` parameter
222
- * (defaulting to a comma) and returns a string created by joining all elements of the array after
223
- * converting it to an array.
196
+ * Join all elements into a string.
197
+ * @param separator - Separator string.
198
+ * @returns Concatenated string.
199
+ * @remarks Time O(n), Space O(n)
224
200
  */
225
201
  join(separator = ',') {
226
202
  return this.toArray().join(separator);
227
203
  }
228
204
  /**
229
- * Time Complexity: O(n)
230
- * Space Complexity: O(n)
231
- *
232
- * The function `toReversedArray` takes an array and returns a new array with its elements in reverse
233
- * order.
234
- * @returns The `toReversedArray()` function returns an array of elements of type `E` in reverse
235
- * order.
205
+ * Snapshot elements into a reversed array.
206
+ * @returns New reversed array.
207
+ * @remarks Time O(n), Space O(n)
236
208
  */
237
209
  toReversedArray() {
238
210
  const array = [];
@@ -241,21 +213,6 @@ export class LinearBase extends IterableElementBase {
241
213
  }
242
214
  return array;
243
215
  }
244
- /**
245
- * Time Complexity: O(n)
246
- * Space Complexity: O(1)
247
- *
248
- * The `reduceRight` function in TypeScript iterates over an array from right to left and applies a
249
- * callback function to each element, accumulating a single result.
250
- * @param callbackfn - The `callbackfn` parameter in the `reduceRight` method is a function that will
251
- * be called on each element in the array from right to left. It takes four arguments:
252
- * @param {U} [initialValue] - The `initialValue` parameter in the `reduceRight` method is an
253
- * optional parameter that specifies the initial value of the accumulator. If provided, the
254
- * `accumulator` will start with this initial value before iterating over the elements of the array.
255
- * If `initialValue` is not provided, the accumulator will
256
- * @returns The `reduceRight` method is returning the final accumulated value after applying the
257
- * callback function to each element in the array from right to left.
258
- */
259
216
  reduceRight(callbackfn, initialValue) {
260
217
  let accumulator = initialValue ?? 0;
261
218
  for (let i = this.length - 1; i >= 0; i--) {
@@ -264,20 +221,11 @@ export class LinearBase extends IterableElementBase {
264
221
  return accumulator;
265
222
  }
266
223
  /**
267
- * Time Complexity: O(m)
268
- * Space Complexity: O(m)
269
- *
270
- * The `slice` function in TypeScript creates a new instance by extracting a portion of elements from
271
- * the original instance based on the specified start and end indices.
272
- * @param {number} [start=0] - The `start` parameter in the `slice` method represents the index at
273
- * which to begin extracting elements from an array-like object. If no `start` parameter is provided,
274
- * the default value is 0, meaning the extraction will start from the beginning of the array.
275
- * @param {number} end - The `end` parameter in the `slice` method represents the index at which to
276
- * end the slicing. By default, if no `end` parameter is provided, it will slice until the end of the
277
- * array (i.e., `this.length`).
278
- * @returns The `slice` method is returning a new instance of the object with elements sliced from
279
- * the specified start index (default is 0) to the specified end index (default is the length of the
280
- * object).
224
+ * Create a shallow copy of a subrange.
225
+ * @param start - Inclusive start (supports negative index).
226
+ * @param end - Exclusive end (supports negative index).
227
+ * @returns New list with the range (`this` type).
228
+ * @remarks Time O(n), Space O(n)
281
229
  */
282
230
  slice(start = 0, end = this.length) {
283
231
  start = start < 0 ? this.length + start : start;
@@ -289,48 +237,36 @@ export class LinearBase extends IterableElementBase {
289
237
  return newList;
290
238
  }
291
239
  /**
292
- * Time Complexity: O(n)
293
- * Space Complexity: O(1)
294
- *
295
- * The `fill` function in TypeScript fills a specified range in an array-like object with a given
296
- * value.
297
- * @param {E} value - The `value` parameter in the `fill` method represents the element that will be
298
- * used to fill the specified range in the array.
299
- * @param [start=0] - The `start` parameter specifies the index at which to start filling the array
300
- * with the specified value. If not provided, it defaults to 0, indicating the beginning of the
301
- * array.
302
- * @param end - The `end` parameter in the `fill` function represents the index at which the filling
303
- * of values should stop. It specifies the end of the range within the array where the `value` should
304
- * be filled.
305
- * @returns The `fill` method is returning the modified object (`this`) after filling the specified
306
- * range with the provided value.
240
+ * Fill a range with a value.
241
+ * @param value - Value to set.
242
+ * @param start - Inclusive start.
243
+ * @param end - Exclusive end.
244
+ * @returns This list.
245
+ * @remarks Time O(n), Space O(1)
307
246
  */
308
247
  fill(value, start = 0, end = this.length) {
309
- // Handling negative indexes
310
248
  start = start < 0 ? this.length + start : start;
311
249
  end = end < 0 ? this.length + end : end;
312
- // Boundary processing
313
250
  if (start < 0)
314
251
  start = 0;
315
252
  if (end > this.length)
316
253
  end = this.length;
317
254
  if (start >= end)
318
255
  return this;
319
- // Iterate through the specified range and fill in the values
320
256
  for (let i = start; i < end; i++) {
321
257
  this.setAt(i, value);
322
258
  }
323
259
  return this;
324
260
  }
325
261
  }
262
+ /**
263
+ * Linked-list specialized linear container.
264
+ * @template E - Element type.
265
+ * @template R - Return type for mapped/derived views.
266
+ * @template NODE - Linked node type.
267
+ * @remarks Time O(1), Space O(1)
268
+ */
326
269
  export class LinearLinkedBase extends LinearBase {
327
- /**
328
- * The constructor initializes the LinearBase class with optional options, setting the maximum length
329
- * if provided and valid.
330
- * @param [options] - The `options` parameter is an optional object that can be passed to the
331
- * constructor. It is of type `LinearBaseOptions<E, R>`. This object may contain properties such as
332
- * `maxLen`, which is a number representing the maximum length. If `maxLen` is a positive integer,
333
- */
334
270
  constructor(options) {
335
271
  super(options);
336
272
  if (options) {
@@ -340,23 +276,13 @@ export class LinearLinkedBase extends LinearBase {
340
276
  }
341
277
  }
342
278
  /**
343
- * Time Complexity: O(n)
344
- * Space Complexity: O(1)
345
- *
346
- * The function overrides the indexOf method to improve performance by searching for an element in a
347
- * custom array implementation starting from a specified index.
348
- * @param {E} searchElement - The `searchElement` parameter is the element that you are searching for
349
- * within the array. The `indexOf` method will return the index of the first occurrence of this
350
- * element within the array.
351
- * @param {number} [fromIndex=0] - The `fromIndex` parameter in the `indexOf` method specifies the
352
- * index in the array at which to start the search for the `searchElement`. If provided, the search
353
- * will begin at the specified index and continue to the end of the array. If not provided, the
354
- * search will start at index
355
- * @returns The `indexOf` method is returning the index of the `searchElement` if it is found in the
356
- * array starting from the `fromIndex`. If the `searchElement` is not found, it returns -1.
279
+ * Linked-list optimized `indexOf` (forwards scan).
280
+ * @param searchElement - Value to match.
281
+ * @param fromIndex - Start position.
282
+ * @returns Index or `-1`.
283
+ * @remarks Time O(n), Space O(1)
357
284
  */
358
285
  indexOf(searchElement, fromIndex = 0) {
359
- // In order to improve performance, it is best to override this method in the subclass of the array implementation
360
286
  const iterator = this._getIterator();
361
287
  let current = iterator.next();
362
288
  let index = 0;
@@ -373,26 +299,13 @@ export class LinearLinkedBase extends LinearBase {
373
299
  return -1;
374
300
  }
375
301
  /**
376
- * Time Complexity: O(n)
377
- * Space Complexity: O(1)
378
- *
379
- * The function overrides the lastIndexOf method in TypeScript to improve performance by searching
380
- * for an element in reverse order starting from a specified index.
381
- * @param {E} searchElement - The `searchElement` parameter is the element that you want to find
382
- * within the array. The `lastIndexOf` method searches the array for this element starting from the
383
- * end of the array (or from the specified `fromIndex` if provided) and returns the index of the last
384
- * occurrence of the element
385
- * @param {number} fromIndex - The `fromIndex` parameter in the `lastIndexOf` method specifies the
386
- * index at which to start searching for the `searchElement` in the array. If provided, the search
387
- * will begin at this index and move towards the beginning of the array. If not provided, the search
388
- * will start at the
389
- * @returns The `lastIndexOf` method is being overridden to search for the `searchElement` starting
390
- * from the specified `fromIndex` (defaulting to the end of the array). It iterates over the array in
391
- * reverse order using a custom iterator `_getReverseIterator` and returns the index of the last
392
- * occurrence of the `searchElement` if found, or -1 if not found.
302
+ * Linked-list optimized `lastIndexOf` (reverse scan).
303
+ * @param searchElement - Value to match.
304
+ * @param fromIndex - Start position.
305
+ * @returns Index or `-1`.
306
+ * @remarks Time O(n), Space O(1)
393
307
  */
394
308
  lastIndexOf(searchElement, fromIndex = this.length - 1) {
395
- // In order to improve performance, it is best to override this method in the subclass of the array implementation
396
309
  const iterator = this._getReverseIterator();
397
310
  let current = iterator.next();
398
311
  let index = this.length - 1;
@@ -408,18 +321,6 @@ export class LinearLinkedBase extends LinearBase {
408
321
  }
409
322
  return -1;
410
323
  }
411
- /**
412
- * Time Complexity: O(n + m)
413
- * Space Complexity: O(n + m)
414
- *
415
- * The `concat` function in TypeScript overrides the default behavior to concatenate items into a new
416
- * list, handling both individual elements and instances of `LinearBase`.
417
- * @param {(E | LinearBase<E, R>)[]} items - The `concat` method you provided takes in a variable
418
- * number of arguments of type `E` or `LinearBase<E, R>`. The method concatenates these items to the
419
- * current list and returns a new list with the concatenated items.
420
- * @returns The `concat` method is returning a new instance of the class that it belongs to, with the
421
- * items passed as arguments concatenated to it.
422
- */
423
324
  concat(...items) {
424
325
  const newList = this.clone();
425
326
  for (const item of items) {
@@ -433,21 +334,13 @@ export class LinearLinkedBase extends LinearBase {
433
334
  return newList;
434
335
  }
435
336
  /**
436
- * Time Complexity: O(m)
437
- * Space Complexity: O(m)
438
- *
439
- * The `slice` method is overridden to improve performance by creating a new instance and iterating
440
- * through the array to extract a subset based on the specified start and end indices.
441
- * @param {number} [start=0] - The `start` parameter in the `slice` method specifies the index at
442
- * which to begin extracting elements from the array. If no `start` parameter is provided, the
443
- * default value is 0, indicating that extraction should start from the beginning of the array.
444
- * @param {number} end - The `end` parameter in the `slice` method represents the index at which to
445
- * end the slicing of the array. If not provided, it defaults to the length of the array.
446
- * @returns The `slice` method is returning a new instance of the array implementation with elements
447
- * sliced from the original array based on the `start` and `end` parameters.
337
+ * Slice via forward iteration (no random access required).
338
+ * @param start - Inclusive start (supports negative index).
339
+ * @param end - Exclusive end (supports negative index).
340
+ * @returns New list (`this` type).
341
+ * @remarks Time O(n), Space O(n)
448
342
  */
449
343
  slice(start = 0, end = this.length) {
450
- // In order to improve performance, it is best to override this method in the subclass of the array implementation
451
344
  start = start < 0 ? this.length + start : start;
452
345
  end = end < 0 ? this.length + end : end;
453
346
  const newList = this._createInstance();
@@ -465,78 +358,48 @@ export class LinearLinkedBase extends LinearBase {
465
358
  return newList;
466
359
  }
467
360
  /**
468
- * Time Complexity: O(n + m)
469
- * Space Complexity: O(m)
470
- *
471
- * The function overrides the splice method to handle deletion and insertion of elements in a data
472
- * structure while returning the removed elements.
473
- * @param {number} start - The `start` parameter in the `splice` method indicates the index at which
474
- * to start modifying the array.
475
- * @param {number} [deleteCount=0] - The `deleteCount` parameter in the `splice` method specifies the
476
- * number of elements to remove from the array starting at the specified `start` index. If
477
- * `deleteCount` is not provided, it defaults to 0, meaning no elements will be removed but new
478
- * elements can still be inserted at
479
- * @param {E[]} items - The `items` parameter in the `splice` method represents the elements that
480
- * will be inserted into the array at the specified `start` index. These elements can be of any type
481
- * and there can be multiple elements passed as arguments to be inserted into the array.
482
- * @returns The `splice` method is returning a new instance of the data structure that was modified
483
- * by removing elements specified by the `start` and `deleteCount` parameters, and inserting new
484
- * elements provided in the `items` array.
361
+ * Splice by walking node iterators from the start index.
362
+ * @param start - Start index.
363
+ * @param deleteCount - How many elements to remove.
364
+ * @param items - Elements to insert after the splice point.
365
+ * @returns Removed elements as a new list (`this` type).
366
+ * @remarks Time O(n + m), Space O(min(n, m)) where `m = items.length`
485
367
  */
486
368
  splice(start, deleteCount = 0, ...items) {
487
- const removedList = this._createInstance(); // Used to store deleted elements
488
- // Handling negative indexes
369
+ const removedList = this._createInstance();
489
370
  start = start < 0 ? this.length + start : start;
490
- start = Math.max(0, Math.min(start, this.length)); // Correct start range
491
- deleteCount = Math.max(0, deleteCount); // Make sure deleteCount is non-negative
371
+ start = Math.max(0, Math.min(start, this.length));
372
+ deleteCount = Math.max(0, deleteCount);
492
373
  let currentIndex = 0;
493
374
  let currentNode = undefined;
494
375
  let previousNode = undefined;
495
- // Find the starting point using an iterator
496
376
  const iterator = this._getNodeIterator();
497
377
  for (const node of iterator) {
498
378
  if (currentIndex === start) {
499
- currentNode = node; // Find the starting node
379
+ currentNode = node;
500
380
  break;
501
381
  }
502
- previousNode = node; // Update the previous node
382
+ previousNode = node;
503
383
  currentIndex++;
504
384
  }
505
- // Delete nodes
506
385
  for (let i = 0; i < deleteCount && currentNode; i++) {
507
- removedList.push(currentNode.value); // Store the deleted value in removedList
508
- const nextNode = currentNode.next; // Save next node
509
- this.delete(currentNode); // Delete current node
386
+ removedList.push(currentNode.value);
387
+ const nextNode = currentNode.next;
388
+ this.delete(currentNode);
510
389
  currentNode = nextNode;
511
390
  }
512
- // Insert new value
513
391
  for (let i = 0; i < items.length; i++) {
514
392
  if (previousNode) {
515
- this.addAfter(previousNode, items[i]); // Insert after previousNode
516
- previousNode = previousNode.next; // Move to newly inserted node
393
+ this.addAfter(previousNode, items[i]);
394
+ previousNode = previousNode.next;
517
395
  }
518
396
  else {
519
- this.addAt(0, items[i]); // Insert at the head of the linked list
520
- previousNode = this._getNodeIterator().next().value; // Update the head node to be the first inserted node
397
+ this.addAt(0, items[i]);
398
+ previousNode = this._getNodeIterator().next().value;
521
399
  }
522
400
  }
523
401
  return removedList;
524
402
  }
525
- /**
526
- * Time Complexity: O(n)
527
- * Space Complexity: O(1)
528
- *
529
- * The function `reduceRight` iterates over an array in reverse order and applies a callback function
530
- * to each element, accumulating a single result.
531
- * @param callbackfn - The `callbackfn` parameter is a function that will be called on each element
532
- * of the array from right to left. It takes four arguments:
533
- * @param {U} [initialValue] - The `initialValue` parameter is an optional value that is used as the
534
- * initial accumulator value in the reduce operation. If provided, the reduce operation starts with
535
- * this initial value and iterates over the elements of the array, applying the callback function to
536
- * each element and the current accumulator value. If `initial
537
- * @returns The `reduceRight` method is returning the final accumulated value after applying the
538
- * callback function to each element in the array from right to left.
539
- */
540
403
  reduceRight(callbackfn, initialValue) {
541
404
  let accumulator = initialValue ?? 0;
542
405
  let index = this.length - 1;