sameGap

Category: Arrays
Author: Stuart Reges
Book Chapter: 7.2
Problem: sameGap
  Write a static method called sameGap that takes an array
   of integers as a parameter and that returns whether or not the gap between
   successive values in the array is always the same.  The gap between
   successive values is defined to be the absolute value of the difference
   between the two values.  For example, consider the following sequence:

        [1, 4, 7, 10, 13, 10, 13, 10, 7, 4]

   Each successive pair of values has a gap of 3.  The first pair of values is
   1 and 4, which are 3 apart.  The second pair of values is 4 and 7, which are
   3 apart.  The third pair of values is 7 and 10, which are 3 apart.  Notice
   that sometimes the first value is larger, as in the pair of values 13
   followed by 10 or 10 followed by 7.  These still have a gap of 3 because we
   use the absolute value of the difference.

   Your method should return true if passed an array with fewer than 2 values.
   Below are examples of arrays and the value that should be returned for each:

        Contents of array                   Value returned
        passed to sameGap                   by sameGap
        ---------------------------         --------------
        {}                                       true
        {42}                                     true
        {10, 15}                                 true
        {1, 4, 7, 10, 13, 10, 13, 10, 7, 4}      true
        {1, 4, 10, 13, 10, 13, 10, 7, 4}         false
        {2, 4, 6, 8, 10}                         true
        {2, 4, 6, 8, 10, 11}                     false
        {1, 2, 3, 4, 5, 6}                       true
        {1, 2, 3, 2, 3, 4, 5, 6}                 true
        {1, 2, 3, 2, 4, 5, 6}                    false
        {3, 3, 3}                                true

   You may use the Math.abs method to find the absolute value.