Compares two strings to each other. If they are equivalent, a zero is returned. Otherwise, most of these routines will return a positive or negative result corresponding to whether stringA is lexicographically greater than, or less than, respectively, than stringB.
if stringA > stringB return 1
if stringA < stringB return -1
if stringA = stringB return 0
Install
Install all functions of strman
yarn add strmanor just the compare function
yarn add strman.compareUsage
import { compare } from 'strman'
// OR
import compare from 'strman.compare'Parameters:
| Name | Type | Description |
|---|---|---|
stringA |
String | String for the comparative |
stringB |
String | String to be compared |
- Source:
Returns:
- Type
- Number
Example
compare('foo', 'bar')
// => 1