40
5
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
.
Do the truthy/falsy values actually have to be truthy/falsy in our language of choice, or can we use any two distinct and consistent values? – Martin Ender – 2017-09-20T17:36:01.560
1@MartinEnder Any two distinct and consistent values. P.S Sorry for the late response – None – 2017-09-20T18:04:39.040
2The text says you'll be given an array of integers, but that only arrays of positive integers can be insignificant. Should we be prepared for an array of negative integers? – Mark S. – 2017-09-23T12:50:33.093