* Produce as output a collection that is logically equivalent to the input * but which combines identical instances of the same record into one * (record, multiplicity) pair.
()
| 71 | * (record, multiplicity) pair. |
| 72 | */ |
| 73 | consolidate(): MultiSet<T> { |
| 74 | // Check if this looks like a keyed multiset (first item is a tuple of length 2) |
| 75 | if (this.#inner.length > 0) { |
| 76 | const firstItem = this.#inner[0]?.[0] |
| 77 | if (Array.isArray(firstItem) && firstItem.length === 2) { |
| 78 | return this.#consolidateKeyed() |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | // Fall back to original method for unkeyed data |
| 83 | return this.#consolidateUnkeyed() |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Private method for consolidating keyed multisets where keys are strings/numbers |
no test coverage detected