Using Ruby 2.4, I have an array of unique, ordered numbers, for example
[1, 7, 8, 12, 14, 15]
How do I find the first two elements whose differ
Here's an alternate method provided for educational purposes:
arr = [1, 7, 8, 12, 14, 15] arr.each_cons(2).map {|v|v.reduce(:-)}.index(-1)