deno.land / x / rambda@v9.1.1 / source / reduceBy-spec.ts

reduceBy-spec.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import {reduceBy} from 'rambda'
test('R.reduceBy', () => { interface Student { name: string, score: number, }
const reduceToNamesBy = reduceBy( (acc: string[], student: Student) => acc.concat(student.name), [] ) const students = [ {name: 'Lucy', score: 92}, {name: 'Drew', score: 85}, {name: 'Bart', score: 62}, ] const result = reduceToNamesBy(student => { const score = student.score return score < 65 ? 'F' : score < 70 ? 'D' : score < 80 ? 'C' : score < 90 ? 'B' : 'A' }, students) result // $ExpectType { [index: string]: string[]; }})
rambda

Version Info

Tagged at
2 months ago