Consecutive numbers
Write a function that takes a string of digits. Try to break up the digits into consecutive integers. If you can, return them, otherwise, return nil
.
Examples
(consec "121314") ;=> [12 13 14]
(consec "121315") ;=> nil
(consec "444445") ;=> [444 445]
(consec "12") ;=> [1 2]
(consec "1") ; throws error
Thanks to this site for the challenge idea where it is considered Expert in JavaScript.
Please submit your solutions as comments on this gist.
@miner I also found problems with strings with a leading
0
that also contained8
or9
😞 Here's another try, which should also cope with long strings. Here I'm using thestr/starts-with?
idea used by other answers here, rather than building up an entire string based on the initial number only: