10 examples of 'node js compare strings' in JavaScript

Every line of 'node js compare strings' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
603function compare(a, b) {
604 const diff = level(a) - level(b);
605 if (diff !== 0) {
606 return diff;
607 }
608 return util.strcmp(a, b);
609}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

75function compareStrings (a, b) {
76 if (a < b) return -1
77 if (a > b) return +1
78 return 0
79}
127function compareStrings(a, b) {
128 if (a < b) return -1;
129 if (a > b) return +1;
130 return 0;
131}
551function strcmp(left, right) {
552 if (left.length != right.length) {
553 throw "Bad strcmp args";
554 }
555 else if (left.length == 0) {
556 return 0;
557 }
558 else if (left[0] < right[0]) {
559 return -1;
560 }
561 else if (left[0] > right[0]) {
562 return 1;
563 }
564 else {
565 return strcmp(
566 left.substring(1),
567 right.substring(1)
568 );
569 }
570}
195export function compareStringsAsc(a: string, b: string) {
196 return a.localeCompare(b, undefined, { sensitivity: 'base' });
197}
54private compareStringinAsc_(a: string, b: string) {
55 return a.localeCompare(b);
56}
186function strcmp(a, b){
187 if (a < b) {
188 return -1;
189 }
190 if (a > b) {
191 return 1;
192 }
193 return 0;
194}
144function StringComparator(s1, s2) {
145 if ( s1 == s2 ) return 0;
146 return s1 < s2 ? -1 : 1;
147},
68function caseInsensitiveCompare(a: string, b: string): number {
69 return a.localeCompare(b, undefined, {sensitivity: 'base'});
70}
9function compareIgnoreCase(stringA, stringB) {
10 return compare(asBlank(stringA).toUpperCase(), asBlank(stringB).toUpperCase());
11}

Related snippets