Problem 36

Convert numbers to text Recursion Challenge

Given a string, replace every single-digit number (0-9) with its English word equivalent. Non-digit characters and multi-digit numbers should be left unchanged.

Function Signature

numToText(str)

Parameters

  • str — a string that may contain single-digit numbers.

Output

Return a new string with single-digit numbers replaced by words.

Constraints

  • The function must use recursion.
  • The function should accept exactly one argument.

Examples

numToText('5 dogs and 6 ponies') → 'five dogs and six ponies'
numToText('Give me 8 dollars')   → 'Give me eight dollars'