forked from joshlacey/functional-programming-with-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
76 lines (66 loc) · 1.35 KB
/
index.js
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const Cat = (name, age) => {
let state = {
name,
age,
species: 'Cat'
}
return Object.assign(
{},
meower(state),
cuddler(state),
defaultAnimal(state)
)
}
const Dog = (name, age) => {
let state = {
name,
age,
species: 'Dog'
}
return Object.assign(
{},
barker(state),
cuddler(state),
defaultAnimal(state)
)
}
const Snake = (name, age) => {
let state = {
name,
age,
species: 'Snake'
}
return Object.assign(
{},
slitherer(),
hisser(state),
defaultAnimal(state)
)
}
const meower = (state) => ({
meow: () => 'Meow, I\'m a ' + state.species.toLowerCase() +'!'
})
const barker = (state) => ({
bark: () => 'Bark, I\'m a ' + state.species.toLowerCase() +'!'
})
const hisser = (state) => ({
hiss: () => 'Hiss, I\'m a ' + state.species.toLowerCase() +'!'
})
const slitherer = () => ({
slither: () => '~~~~~'
})
const cuddler = (state) => ({
cuddle: () => state.name + ' wants to cuddle!'
})
const defaultAnimal = (state) => ({
bio: () => state.name + ' the ' + state.species.toLowerCase() + ' is ' + state.age.toString() + ' years old.',
eat: () => state.name + ' ate some ' + state.species.toLowerCase() + ' food!',
bite: () => state.name + ' bit you!',
age: () => state.age.toString(),
name: () => state.name
})
module.exports = {
Cat,
Dog,
Snake
}