Implemented toDigits function.