Ascending Consecutive Numbers

Published by Colin Brash in

Write a function that returns true if a string consists of consecutive numbers ascending by 1.

Examples

ascending("232425") ➞ true
// Consecutive numbers 23, 24, 25

ascending("2324256") ➞ false
// No matter how this string is divided, the numbers are not consecutive.

ascending("444445") ➞ true
// Consecutive numbers 444 and 445.

Notes

A number can consist of any number of digits, so long as the numbers are adjacent to each other, and the string has at least two of them.

Watch a quick demo on how Edabit works.