Would you like to clone this notebook?

When you clone a notebook you are able to make changes without affecting the original notebook.

Cancel

String.localeCompare Example

node v8.17.0
version: 2.0.0
endpointsharetweet
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare function areEqualIgnoreCase(str1, str2) { if (!str1 || !str2) { return false; } const result = str1.localeCompare(str2, undefined, { sensitivity: 'base' }); return (result === 0); } function runTestCase(str1, str2) { const areEqual = areEqualIgnoreCase(str1, str2); console.log(`Are ${str1} and ${str2} equal (ignoring case)? ${areEqual}`); } runTestCase('foo', 'bar'); runTestCase('foo', 'foo'); runTestCase('foo', 'FoO'); runTestCase('bar', 'BAR');
Loading…

no comments

    sign in to comment