Travis build: 812 [ci skip]
This commit is contained in:
@ -9,15 +9,15 @@ Return `0` if the `direction` changes or the `direction` if the last element is
|
||||
```js
|
||||
const isArraySorted = arr => {
|
||||
const direction = arr[0] > arr[1] ? -1 : 1;
|
||||
for(let [i, val] of arr.entries())
|
||||
for (let [i, val] of arr.entries())
|
||||
if (i === arr.length - 1) return direction;
|
||||
else if ((val - arr[i + 1]) * direction > 0) return 0;
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
```js
|
||||
isArraySorted([0,1,2,3]) // 1
|
||||
isArraySorted([0,1,2,2]) // 1
|
||||
isArraySorted([4,3,2]) // -1
|
||||
isArraySorted([4,3,5]) // 0
|
||||
isArraySorted([0, 1, 2, 3]); // 1
|
||||
isArraySorted([0, 1, 2, 2]); // 1
|
||||
isArraySorted([4, 3, 2]); // -1
|
||||
isArraySorted([4, 3, 5]); // 0
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user