Number to Words

Hard30 minLinkedIn

Prompt

Write a function numberToWords(num) that takes a non-negative integer and returns its English word form.

numberToWords(18653);
// "eighteen thousand six hundred fifty three"
numberToWords(0);
// "zero"
numberToWords(1000000);
// "one million"

The output uses lowercase words separated by single spaces. No commas, no hyphens, no "and".

Requirements

  • Return the English word form of a non-negative integer
  • numberToWords(0) returns "zero"
  • Words are lowercase, separated by single spaces, with no "and"
  • Support values up to the billions