We can use every()
method of array to check if condition is true for every element of the array. So our solution using every()
method goes like this:
arr1 = [1, 2, 3, 4, 6, 5];
arr2 = [1, 2, 3, 4, 5, 6];
arr1.every((element, index, array) =>
index === 0 || element >= array[index - 1]
)
arr2.every((element, index, array) =>
index === 0 || element >= array[index - 1]
)
Top comments (0)