Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/ayonli_jsext/string/index.ts>compare

A JavaScript extension package for building strong and modern applications.
Latest
function compare
import { compare } from "https://deno.land/x/ayonli_jsext@v0.9.72/string/index.ts";

Compares two strings, returns -1 if a < b, 0 if a === b and 1 if a > b.

NOTE: prefer using String.prototype.localeCompare instead.

Examples

Example 1

import { compare } from "@ayonli/jsext/string";

console.log(compare("a", "b")); // -1
console.log(compare("b", "a")); // 1
console.log(compare("a", "a")); // 0

Parameters

str1: string
str2: string

Returns

-1 | 0 | 1