Your task is to find all the elements of an array that are non consecutive. A number is considered non consecutive if it is not exactly one larger than the previous element in the array. The first element always gets a pass.
You should return the results as an array of objects with two values i: and n: .
Example
For the the array [1,2,3,4,6,7,8,10], the result should be:
nconsecutive([1,2,3,4,6,7,8,10])
[
{'i': 4, 'n': 6},
{'i': 7, 'n': 15}
]
Tests
[6,7,8,9,11,12]
[100,101,102,112,113,114,129]
Good luck!
This challenge comes from thecodeite on CodeWars. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge idea for a future post? Email yo+challenge@dev.to with your suggestions!