This is a function from a book that I am working through:
function byQuery(query) {
return function(item) {
return !query ||
item.name.toLowerCase().includes(query.toLowerCase());
}
}
Its purpose is to filter a list of objects--but I am not sure where item is coming from--its only use (in the given code) is like so:
<List list={(list || []).filter(byQuery(query))} />
item comes from the argument that filter provides to its callback function. byQuery(query) returns a function is basically the function that is used by filter. It would be similar to this
{(list || []).filter(function(item) {
return !query ||
item.name.toLowerCase().includes(query.toLowerCase());
})}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With