generated from dr-btd-student/p2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake-multi-filter.js
More file actions
37 lines (32 loc) · 1.22 KB
/
make-multi-filter.js
File metadata and controls
37 lines (32 loc) · 1.22 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
'use strict';
// Define the MakeMultiFilter function
function MakeMultiFilter(originalArray) {
// Make a copy of the original array
let currentArray = [...originalArray];
// Define the arrayFilterer function
function arrayFilterer(filterCriteria, callback) {
// If filterCriteria is a function, filter the current array
if (typeof filterCriteria === 'function') {
currentArray = currentArray.filter(filterCriteria);
} else {
// If filterCriteria is not a function, return the current array
return currentArray;
}
// If callback is a function, call it with the current array
if (typeof callback === 'function') {
callback.call(originalArray, currentArray);
}
// Return the arrayFilterer function for chaining
return arrayFilterer;
}
// Return the arrayFilterer function
return arrayFilterer;
}
// Check if we're in a Node.js environment
if (typeof module !== 'undefined') {
// If so, export the MakeMultiFilter function
module.exports = MakeMultiFilter;
} else {
// If not, we're in a browser environment, so attach MakeMultiFilter to the window object
window.MakeMultiFilter = MakeMultiFilter;
}