Find missing elements in an ordered array consists of number sequences (Ruby) : In an ordered array, how to find the missing elements in an ordered array? with a condition that the missing elements have to be one of the existing element (represent by `v`) + 1 or v - 1. The smallest element is 0.

e.g.

[0, 1, 2, 4, 5, 6, 9, 10, 12, 13, 17]

returns

[3, 7, 8, 11, 14, 16, 18]