-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathallPass.js
54 lines (51 loc) · 1.02 KB
/
allPass.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
const R = require('ramda');
const {allPass, propEq, map, compose, filter, project} = R;
const needs = ['wifi', 'shower', 'laundry'];
const homes = [{
name: 'Home 1',
wifi: 'y',
shower: 'y',
laundry: 'y',
metro: 'n',
balcony: 'y',
fireplace: 'n',
pool: 'y'
}, {
name: 'Home 2',
wifi: 'n',
shower: 'y',
laundry: 'y',
metro: 'n',
balcony: 'n',
fireplace: 'n',
pool: 'n'
}, {
name: 'Home 3',
wifi: 'y',
shower: 'y',
laundry: 'y',
metro: 'n',
balcony: 'y',
fireplace: 'y',
pool: 'n'
}, {
name: 'Home 4',
wifi: 'y',
shower: 'y',
laundry: 'n',
metro: 'n',
balcony: 'n',
fireplace: 'n',
pool: 'n'
}];
const allNeedsMatchY = allPass(
map(propEq(R.__, 'y'), needs)
);
const filterNeeds = filter(allNeedsMatchY);
const getNameWithNeeds = project([...needs, 'name']);
const getMatchedHomeNameAndNeeds = compose(
getNameWithNeeds,
filterNeeds
);
const result = getMatchedHomeNameAndNeeds(homes);
console.log(result);