On Wed, Jun 27, 2018 at 4:37 PM, Robert Wozniak <wozniakj.rob...@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
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to