diff --git a/packages/collection/src/collection.ts b/packages/collection/src/collection.ts index 787e57f71..9e2930ef4 100644 --- a/packages/collection/src/collection.ts +++ b/packages/collection/src/collection.ts @@ -1023,7 +1023,10 @@ export class Collection extends Map { * but returns a Collection instead of an Array. */ public toReversed() { - return new this.constructor[Symbol.species](this).reverse(); + const entries = [...this.entries()]; + entries.reverse(); + + return new this.constructor[Symbol.species](entries); } /** @@ -1039,7 +1042,10 @@ export class Collection extends Map { * ``` */ public toSorted(compareFunction: Comparator = Collection.defaultSort): Collection { - return new this.constructor[Symbol.species](this).sort(compareFunction); + const entries = [...this.entries()]; + entries.sort((a, b): number => compareFunction(a[1], b[1], a[0], b[0])); + + return new this.constructor[Symbol.species](entries); } public toJSON() {