I've looked around and have not found any answers for this. The problem seems pretty simple at first.
Let's say we have an array like this. We can assume that the array will ALWAYS have some equal thing it counts up by (each element has the same difference between the elements adjacent to it).
[1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2.0]
The answer to above would be 0.1
.
Another example might be an array like this.
[0.2,0.4,0.6,0.8,1.0,1.2,1.4]
This answer would be 0.2
One possible solution is I could read the first and second parameters of the array and capture the difference and that will be my 'step'. Is this the best way to go about doing this? Is there any downsides to this approach?
if the array was counting downward like this:
[0.8,0.6,0.4,0.2]
, then how could I extract the step successfully?
In this case I need the answer -0.2
, my answer would not work, and taking the absolute value would give me 0.2
not -0.2
.