Remove indexer from hints, add indexBy

This commit is contained in:
Jon Staab
2024-05-30 15:04:23 -07:00
parent a4948fe5dc
commit 35eccf7467
4 changed files with 19 additions and 18 deletions
+10
View File
@@ -230,6 +230,16 @@ export const groupBy = <T, K>(f: (x: T) => K, xs: T[]) => {
return r
}
export const indexBy = <T, K>(f: (x: T) => K, xs: T[]) => {
const r = new Map<K, T>()
for (const x of xs) {
r.set(f(x), x)
}
return r
}
export const sample = <T>(n: number, xs: T[]) => {
const result: T[] = []
const limit = Math.min(n, xs.length)