Sobes.tech
Junior — Senior

Checking an array for monotonicity

livecode

Task condition

Implement a function that receives an array of numbers and determines whether it maintains a single direction (non-decreasing or non-increasing). The function should return true if the array is monotonic, and false otherwise.

function isMonotonic(arr) {
    // your code here
}

isMonotonic([1, 2, 3, 6]); // true  
isMonotonic([6, 3, 3, 2, 1]); // true  
isMonotonic([1, 1, 1]); // true  
isMonotonic([1, 10, 6]); // false