Giovanni Azua - 1 year ago 58

Scala Question

I have an array

`val x : Array[Double]`

`x(i) <= x(i+1)`

`i`

`foldLeft`

`foldRight`

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

Consider this:

```
def isMonotonic(arr:Array[Int]) =
if (arr.isEmpty) true
else (arr, arr.tail).zipped.forall {case (a,b) => a <= b}
```

Simplified solution (thanks to @som-snytt):

```
def isMonotonic(arr:Array[Int]) =
(arr, arr.drop(1)).zipped.forall (_ <= _)
```