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

Function sortByKeyAndIndex

packages/db-ivm/tests/operators/orderByWithIndex.test.ts:438–458  ·  view source on GitHub ↗

* Helper function to sort results by key and then index

(results: Array<any>)

Source from the content-addressed store, hash-verified

436 * Helper function to sort results by key and then index
437 */
438function sortByKeyAndIndex(results: Array<any>) {
439 return [...results]
440 .sort(
441 (
442 [[_aKey, [_aValue, _aIndex]], aMultiplicity],
443 [[_bKey, [_bValue, _bIndex]], bMultiplicity],
444 ) => aMultiplicity - bMultiplicity,
445 )
446 .sort(
447 (
448 [[aKey, [_aValue, _aIndex]], _aMultiplicity],
449 [[bKey, [_bValue, _bIndex]], _bMultiplicity],
450 ) => aKey - bKey,
451 )
452 .sort(
453 (
454 [[_aKey, [_aValue, _aIndex]], _aMultiplicity],
455 [[_bKey, [_bValue, _bIndex]], _bMultiplicity],
456 ) => _aIndex - _bIndex,
457 )
458}

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected