Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make `where not` case?

I need where but with not case. For example, I would like to find plays, which have no name "Shakespeare":

_.where(listOfPlays, {author: !"Shakespeare", year: 1611});
                              ^^^^^^^^^^^^^
                            NOT Shakespeare

How can I do it with underscore?

like image 238
Warlock Avatar asked Oct 01 '14 14:10

Warlock


People also ask

How do you make a search not case-sensitive?

Yes you can do it using both side ToUpper() or ToLower() function in your filter condition. in that case user type lower or upper case but search method will for both side.

How do I ignore case in SQL search?

To do a case-insensitive comparison, use the ILIKE keyword; e.g., column ILIKE 'aBc' and column ILIKE 'ABC' both return TRUE for 'abc' . In contrast, MySQL and MS SQL Server have case-insensitive behaviors by default. This means WHERE column = 'abc' returns TRUE for e.g., 'abc' , 'ABC' , or 'aBc' .

Is == case-sensitive in python?

Python strings equality can be checked using == operator or __eq__() function. Python strings are case sensitive, so these equality check methods are also case sensitive.

How do I make JavaScript not case-sensitive?

The most basic way to do case insensitive string comparison in JavaScript is using either the toLowerCase() or toUpperCase() method to make sure both strings are either all lowercase or all uppercase.


1 Answers

_.filter(listOfPlays, function(play) {
    return play.author !== 'Shakespeare' && play.year === 1611;
});

http://underscorejs.org/#filter

where is nothing more than a convenient wrapper around filter:

// Convenience version of a common use case of `filter`: selecting only objects
// containing specific `key:value` pairs.
_.where = function(obj, attrs) {
    return _.filter(obj, _.matches(attrs));
};

https://github.com/jashkenas/underscore/blob/a6c404170d37aae4f499efb185d610e098d92e47/underscore.js#L249

like image 107
jgillich Avatar answered Sep 20 '22 07:09

jgillich