[Proposal] ignoreCase method

T.J. Crowder tj.crowder at farsightsoftware.com
Wed Jun 27 16:13:15 UTC 2018


On Wed, Jun 27, 2018 at 4:37 PM, Robert Wozniak <wozniakj.robert at gmail.com>
wrote:
> ...it does compare case sensitive strings but
> it doesn’t compare strings in an array and to do it, you will have to
> execute the method as many times as strings in an array

That's not a problem. For the "does this string match any in this array"
case, use `Array#some`:

```js
const stringOne = "Matheus";
const manyStrings = ['robert', 'lucas', 'matheus'];
if (manyStrings.some(s => s.localeCompare(stringOne, undefined,
{sensitivity: "base"}) == 0)) {
    // Yes, it was found
}
```

(`.localeCompare(stringOne, undefined, {sensitivity: "base"})` **is**
fairly verbose, so I'd probably have a utility function for it.)

> ...and the method will do it for you inside.

There's not all that much in it, doing the loop within the standard API
function vs. outside it. If it's a hotspot for execution, it'll get
aggressively optimized either way. If it isn't, you don't care.

-- T.J. Crowder
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180627/ce18039f/attachment.html>


More information about the es-discuss mailing list