Update snippet descriptions
This commit is contained in:
@ -3,11 +3,11 @@ title: isSorted
|
||||
tags: array,intermediate
|
||||
---
|
||||
|
||||
Returns `1` if a numeric array is sorted in ascending order, `-1` if it is sorted in descending order or `0` if it is not sorted.
|
||||
Checks if a numeric array is sorted.
|
||||
|
||||
- Calculate the ordering `direction` for the first pair of adjacent array elements.
|
||||
- Return `0` if the given array is empty, only has one element or the `direction` changes for any pair of adjacent array elements.
|
||||
- Use `Math.sign()` to covert the final value of `direction` to `-1` or `1`.
|
||||
- Use `Math.sign()` to covert the final value of `direction` to `-1` (descending order) or `1` (ascending order).
|
||||
|
||||
```js
|
||||
const isSorted = arr => {
|
||||
|
||||
Reference in New Issue
Block a user