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!
Top comments (18)
Here's mine
Bravo! You did what I could not 😂
You could. You just need to go on step forward
Here is the simple solution with Python:
Rust:
huhuhu iterator
TypeScript
Haskell solution:
Test results:
Ruby
for clarification, from the challenge:
Python solution 🐍
solution in Nim:
A python solution: