MCPcopy Create free account
hub / github.com/TanStack/db / mapToSortedArray

Function mapToSortedArray

packages/db-ivm/tests/test-utils.ts:81–92  ·  view source on GitHub ↗
(
  map: Map<string, T>,
  compare?: (a: T, b: T) => number,
)

Source from the content-addressed store, hash-verified

79 * Convert a Map back to a sorted array for comparison
80 */
81export function mapToSortedArray<T>(
82 map: Map<string, T>,
83 compare?: (a: T, b: T) => number,
84): Array<T> {
85 const compareFn =
86 compare ??
87 ((a: T, b: T) => {
88 // Sort by JSON string representation for consistent ordering
89 return JSON.stringify(a).localeCompare(JSON.stringify(b))
90 })
91 return Array.from(map.values()).sort(compareFn)
92}
93
94/**
95 * Create expected result set as a Map

Callers 2

getResultMethod · 0.85
assertResultsFunction · 0.85

Calls 2

fromMethod · 0.80
valuesMethod · 0.45

Tested by

no test coverage detected