Fix sortBy to work with more data types, add kind 10014

This commit is contained in:
Jon Staab
2024-06-20 10:19:32 -07:00
parent 760e0a99b4
commit 22a5fb58b4
7 changed files with 22 additions and 16 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@welshman/lib",
"version": "0.0.9",
"version": "0.0.10",
"author": "hodlbod",
"license": "MIT",
"description": "A collection of utilities.",
+7 -2
View File
@@ -209,8 +209,13 @@ export const uniqBy = <T>(f: (x: T) => any, xs: T[]) => {
export const sort = <T>(xs: T[]) => [...xs].sort()
export const sortBy = <T>(f: (x: T) => number, xs: T[]) =>
[...xs].sort((a: T, b: T) => f(a) - f(b))
export const sortBy = <T>(f: (x: T) => any, xs: T[]) =>
[...xs].sort((a: T, b: T) => {
const x = f(a)
const y = f(b)
return x < y ? -1 : x > y ? 1 : 0
})
export const groupBy = <T, K>(f: (x: T) => K, xs: T[]) => {
const r = new Map<K, T[]>()