An insignificant array is an array of positive integers, where the absolute differences between consecutive elements are all smaller than or equal to 1.
For example, the following array is insignificant:
[1, 2, 3, 4, 3, 4, 5, 5, 5, 4]
Because the corresponding (absolute) differences are:
[1, 1, 1, 1, 1, 1, 0, 0, 1]
Which are all smaller than or equal to 1.
Your task is to determine whether a given array of integers is insignificant.
- You may assume that the array always contains at least two elements.
- Standard input and output rules apply. You may take input (and output) in any reasonable format.
- Default Loopholes are forbidden.
- The truthy / falsy values have to be distinct and consistent.
- This is code-golf, so shortest answer in bytes wins.
Test cases
Input -> Output [1, 2, 3, 4, 3, 4, 5, 5, 5, 4] -> true [1, 2, 3, 4, 5, 6, 7, 8, 9, 8] -> true [3, 3, 3, 3, 3, 3, 3] -> true [3, 4, 4, 4, 3, 3, 3, 4, 4, 4] -> true [1, 2, 3, 4] -> true [5, 4, 3, 2] -> true [1, 3, 5, 7, 9, 7, 5, 3, 1] -> false [1, 1, 1, 2, 3, 4, 5, 6, 19] -> false [3, 4, 5, 6, 7, 8, 7, 5] -> false [1, 2, 4, 10, 18, 10, 100] -> false [10, 20, 30, 30, 30] -> false
I used the values true
and false
.