function numberToWords(num) {
  if (num < 21) return UPTO20[num];

  let ans = '';

  for (const [div, word] of HUNDREDS.entries()) {
    if (Math.floor(num/div)) {
      ans += `${ numberToWords(Math.floor(num/div)) } `;
      ans += `${ word } `;
      num %= div;
    }
  }

  if (num && num < 21) {
    ans += UPTO20[num]  + ' ';
  } else {
    if (Math.floor(num/10)) ans += `${ TENS[Math.floor(num/10)] } `;
    if (Math.floor(num % 10)) ans += `${ UPTO20[Math.floor(num % 10)] } `;
  }

  return ans.trim();
}
You are creating a basic number-to-speech algorithms to use at search engine company.
The first part is to convert a given number into its text representation.
The 2nd part, is to take that text and synthetize the voice.
We are going to focus on the first part for this exercise.

Convert a positive integer into its English words representation.

@param {number} num - The positive integer. Should be <= 2^31 - 1
@return {string} - The English words for the given number

@author Adrian Mejia <adrianmejia.com>