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

Function sortByKeyIndexAndId

packages/db-ivm/tests/operators/topKWithIndex.test.ts:452–470  ·  view source on GitHub ↗

* Helper function to sort results by key, then index, then id

(results: Array<any>)

Source from the content-addressed store, hash-verified

450 * Helper function to sort results by key, then index, then id
451 */
452function sortByKeyIndexAndId(results: Array<any>) {
453 return [...results].sort(
454 (
455 [[aKey, [aValue, aIndex]], _aMultiplicity],
456 [[bKey, [bValue, bIndex]], _bMultiplicity],
457 ) => {
458 // First sort by key
459 if (aKey !== bKey) {
460 return aKey < bKey ? -1 : 1
461 }
462 // Then by index
463 if (aIndex !== bIndex) {
464 return aIndex - bIndex
465 }
466 // Then by id if indices are the same
467 return aValue.id - bValue.id
468 },
469 )
470}
471
472/**
473 * Helper function to sort results by multiplicity, then index, then id

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected