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.
A leading "0" caused a problem with my original submission. It's worth testing with inputs like "0123" and "010910". Note that
(Long/parseLong "010")
returns 10, ignoring the leading zero. Also,(read-string "010")
returns 8 as the leading zero is Clojure/Java notation for octal numbers. For this challenge I would not expect to support octal. My interpretation is that a leading zero can only be a single digit zero and all digits are decimal.