Use an array of values that you'd like to compare against, and check for a returned index greater than -1. This indicates the value evaluated was found in the collection.
_.remove( fruits, function ( fruit ) {
return _.indexOf( [ "Apple", "Banana", "Orange" ], fruit ) >= 0;
});
Alternatively you could use lo-dash's _.contains
method to get a boolean response.
The problem with the approach you took was that you weren't comparing fruit
against each one of those strings; instead, the only comparison taking place was fruit
against "Apple"
, after that you were coercing strings all on their own.
Non-empty strings coerce to true
(!!"Banana"
), and as such are truthy. Therefore, the following condition will always short-circuit at "Banana" (unless fruit
strictly equals "Apple"
), returning true
:
return fruit === "Apple" || 'Banana' || "Orange";