MCPcopy Create free account
hub / github.com/blacksmithgu/datacore / sortInPlace

Method sortInPlace

src/api/data-array.ts:305–322  ·  view source on GitHub ↗
(
        key?: (value: T) => U,
        direction?: "asc" | "desc",
        comparator?: ArrayComparator<U>
    )

Source from the content-addressed store, hash-verified

303 }
304
305 public sortInPlace<U>(
306 key?: (value: T) => U,
307 direction?: "asc" | "desc",
308 comparator?: ArrayComparator<U>
309 ): DataArray<T> {
310 if (this.values.length == 0) return this;
311 let realComparator = comparator ?? this.defaultComparator;
312 let realKey = key ?? ((l: T) => l as unknown as U);
313
314 this.values.sort((a, b) => {
315 let aKey = realKey(a);
316 let bKey = realKey(b);
317
318 return direction == "desc" ? -realComparator(aKey, bKey) : realComparator(aKey, bKey);
319 });
320
321 return this;
322 }
323
324 public groupBy<U>(key: ArrayFunc<T, U>, comparator?: ArrayComparator<U>): DataArray<{ key: U; rows: T[] }> {
325 if (this.values.length == 0) return this.lwrap([]);

Callers

nothing calls this directly

Calls 1

sortMethod · 0.65

Tested by

no test coverage detected