mathjs/docs/reference/functions/compareText.md
2022-03-01 13:04:09 +01:00

59 lines
1.7 KiB
Markdown

---
layout: default
---
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
<h1 id="function-comparetext">Function compareText <a href="#function-comparetext" title="Permalink">#</a></h1>
Compare two strings lexically. Comparison is case sensitive.
Returns 1 when x > y, -1 when x < y, and 0 when x == y.
For matrices, the function is evaluated element wise.
<h2 id="syntax">Syntax <a href="#syntax" title="Permalink">#</a></h2>
```js
math.compareText(x, y)
```
<h3 id="parameters">Parameters <a href="#parameters" title="Permalink">#</a></h3>
Parameter | Type | Description
--------- | ---- | -----------
`x` | string &#124; Array &#124; DenseMatrix | First string to compare
`y` | string &#124; Array &#124; DenseMatrix | Second string to compare
<h3 id="returns">Returns <a href="#returns" title="Permalink">#</a></h3>
Type | Description
---- | -----------
number &#124; Array &#124; DenseMatrix | Returns the result of the comparison: 1 when x > y, -1 when x < y, and 0 when x == y.
<h3 id="throws">Throws <a href="#throws" title="Permalink">#</a></h3>
Type | Description
---- | -----------
<h2 id="examples">Examples <a href="#examples" title="Permalink">#</a></h2>
```js
math.compareText('B', 'A') // returns 1
math.compareText('2', '10') // returns 1
math.compare('2', '10') // returns -1
math.compareNatural('2', '10') // returns -1
math.compareText('B', ['A', 'B', 'C']) // returns [1, 0, -1]
```
<h2 id="see-also">See also <a href="#see-also" title="Permalink">#</a></h2>
[equal](equal.html),
[equalText](equalText.html),
[compare](compare.html),
[compareNatural](compareNatural.html)