forked from jsmapr1/simplifying-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpartial.js
More file actions
84 lines (73 loc) · 1.7 KB
/
Copy pathpartial.js
File metadata and controls
84 lines (73 loc) · 1.7 KB
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
77
78
79
80
81
82
83
84
/* eslint-disable no-unused-vars */
// START:info
const building = {
hours: '8 a.m. - 8 p.m.',
address: 'Jayhawk Blvd',
};
const manager = {
name: 'Augusto',
phone: '555-555-5555',
};
const program = {
name: 'Presenting Research',
room: '415',
hours: '3 - 6',
};
const exhibit = {
name: 'Emerging Scholarship',
contact: 'Dyan',
};
// END:info
// START:func
function mergeProgramInformation(building, manager) {
const { hours, address } = building;
const { name, phone } = manager;
const defaults = {
hours,
address,
contact: name,
phone,
};
return program => {
return { ...defaults, ...program };
};
}
// END:func
// START:invoke
const programInfo = mergeProgramInformation(building, manager)(program);
// {
// name: 'Presenting Research',
// room: '415',
// hours: '3 - 6',
// address: 'Jayhawk Blvd',
// contact: 'Augusto',
// phone: '555-555-5555'
// }
const exhibitInfo = mergeProgramInformation(building, manager)(exhibit);
// {
// name: 'Emerging Scholarship',
// contact: 'Dyan'
// hours: '8 a.m. - 8 p.m.',
// address: 'Jayhawk Blvd'
// phone: '555-555-5555'
// }
// END:invoke
function getBirds(...states) {
return ['meadowlark', 'robin', 'roadrunner'];
}
// START:birds
const birds = getBirds('kansas', 'wisconsin', 'new mexico');
// ['meadowlark', 'robin', 'roadrunner']
// END:birds
// START:zip
const zip = (...left) => (...right) => {
return left.map((item, i) => [item, right[i]]);
};
zip('kansas', 'wisconsin', 'new mexico')(...birds);
// [
// ['kansas', 'meadowlark'],
// ['wisconsin', 'robin'],
// ['new mexico', 'roadrunner']
// ]
// END:zip
export { building, manager, exhibit, program, zip, mergeProgramInformation };