-
Notifications
You must be signed in to change notification settings - Fork 0
/
basic.ts
43 lines (33 loc) · 948 Bytes
/
basic.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
33
34
35
36
37
38
39
40
41
42
43
import { get, add, move, update, filter, omit, last, sort } from '../src'
let id = 1
function person (name: string) { return { id: id++, name, alive: true } }
const exBeatles: any[] = []
const beatles = [
person('john lennon'),
person('paul mccartney'),
person('george harrison'),
person('pete best'),
]
// original beatles
console.log(beatles) // john, paul, george, pete
// find pete, passing an alternate key
const pete = get(beatles, 'pete best', 'name')
// get rid of pete
if (pete) {
move(beatles, pete.id, 0, exBeatles)
}
// add ringo
add(beatles, person('ringo star'))
// check last
last(beatles) // ringo star
// sort
sort(beatles, 'name', true, false) // george, john, paul, ringo
// sadly, some beatles are no more
update(beatles, 1, { alive: false })
update(beatles, 3, { alive: false })
// log
console.log({
liveBeatles: filter(beatles, true, 'alive'),
deadBeatles: omit(beatles, true, 'alive'),
exBeatles
})