Hi all,
I am building a recipe table app that pulls in data from an API. I am trying to learn filtering.
In this case, I want to filter by cook time
.
The cook times come in the following formats: 10 mins
, 1 hr
, 1 hr 15 mins
.
For example, recipe object/s might look something like this:
{
recipeName: 'Baked Eggs',
cookTime: '1 hr 25 mins'
},
{
recipeName: 'Scrambled Eggs',
cookTime: '5 mins'
},
{
recipeName: 'Pumpkin Soup',
cookTime: '45 mins'
}
So far I am able to do a strict match and sometimes “include” other cook times with this function:
filter: value => {
if (!selectedCookTime) return true;
if (selectedCookTime.includes("hr")) {
// this captures all recipes of the same "hr"
return value.startsWith(selectedCookTime);
}
// this returns a strict cook time match.
return value === selectedCookTime;
// how to do a match that includes recipes LESS THAN
// and including the selectedCookTime ??
}
But it’s not robust enough to filter table items, say 1 hr 15mins
and below.
Any advice on how to craft this function would be much appreciated.
Thanks in advance!