-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
21 lines (18 loc) · 733 Bytes
/
index.js
File metadata and controls
21 lines (18 loc) · 733 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
const multiFilter = (data, filters) => {
return data.filter((item) => {
return Object.entries(filters).every(([filterProperty, filterValues]) => {
switch(Object.prototype.toString.call(item[filterProperty])){
case '[object Object]':
return Object.entries(filterValues).every(([extFilterProperty, extFilterValue]) => {
return new Map(Object.entries(item[filterProperty])).get(extFilterProperty) === extFilterValue;
});
case '[object Array]':
return item[filterProperty].some((itemValue) => {
return filterValues.includes(itemValue);
});
default:
return filterValues.includes(item[filterProperty]);
}
});
});
}