You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Pulkit Singhal <pu...@gmail.com> on 2012/10/30 07:46:00 UTC

case-insensitive comparison inside js script for map/reduce

I was wondering if there are already utility methods present in CouchDB
1.2.0 that perform a case-insensitive comparison?
I know its really easy to write one but if its there and its already part
of the core JS engine's exposed methods, I would rather not rewrite it.
I like how reusing the sum and avg methods that are already present in
CouchDB, simply makes sense.
So a case-insensitive comparison method is already there then can someone
tell me what its signature looks like exactly?

Thanks!

Re: case-insensitive comparison inside js script for map/reduce

Posted by Jens Alfke <je...@couchbase.com>.
On Oct 29, 2012, at 11:46 PM, Pulkit Singhal <pu...@gmail.com>> wrote:

I was wondering if there are already utility methods present in CouchDB
1.2.0 that perform a case-insensitive comparison?

Not that I know of. You can do this by lowercasing each string and comparing them; or if one of the strings is a constant, you can convert it to a regexp and do a case-insensitive match, i.e. /foobar/i .

(In either case, you may have I18N problems, as most JS implementations seem to have limited Unicode support and may not be able to do this kind of transliteration on non-Roman letters. I’ve had trouble with this in client-side web scripts.)

Or you could just make sure you store normalized (e.g. lowercased) strings in your documents, to avoid the necessity of case-insensitive comparison.

—Jens