I'm working on a project that filters jobs depending on job schedules and personal availability of users.
const jobs: JobRecord[] = [
{
"storeName": "Highwire Coffee Company",
"schedule": [
"Tuesday",
"Thursday",
],
...
},
{
"storeName": "Blue Bottle Coffee",
"rid": "recNgeUMcYhWUxw8b",
"schedule": [
"Thursday",
],
...
},
]
const availability: Availability = {
"friday": false,
"monday": false,
"thursday": true,
"tuesday": false,
"wednesday": true,
}
For example, given these inputs above, I should make a function returning only the job with storename "Blue Bottle Coffee".
To that end, I've written these two functions.
findAvailableDays (availability: Availability){
var availDays: string[];
availDays = [];
for (const [day, avail] of Object.entries(availability)){
if (avail){
availDays.push(day);
}
}
return availDays;
};
filterJobs = (jobs: JobRecord[], availability: Availability): void => {
// Step 0: Clone the jobs input
const newJobs: JobRecord[] = cloneDeep(jobs);
console.log(newJobs, availability);
// Step 1: Remove jobs where the schedule doesn't align with the users' availability.
for (const[store, schedule] of Object.entries(jobs)){
var availDays: string[];
availDays = this.findAvailableDays(availability);
const checkIncludes = (currentValue) => availDays.includes(currentValue);
let checker = (availDays, schedule) => schedule.every(checkIncludes(checkIncludes));
if(!checker(availDays, schedule)){
delete newJobs[store];
}
}
// Step 2: Save into state
this.setState({ jobs: newJobs });
};
However, my every() function in filterJobs always runs into an error (shown below). I've checked that every() accepts functions as arguments (which I made sure), and works on arrays (I believe schedule should be an array, given the example). What am I doing wrong/missing here? Should I try to find another way to go about this?
