'use strict'; 

module.exports = numberWords;

// TODO: Write tests - not 100% yet
// TODO: Minimize calls (MAX takes 32 calls)
// TODO: Add support for “st”, “nd”, “rd” and “th”

var TEN             = 10;
var ONE_HUNDRED     = 100;
var ONE_THOUSAND    = 1000;             // 1.000 (3)
var ONE_MILLION     = 1000000;          // 1.000.000 (6)
var ONE_BILLION     = 1000000000;       // 1.000.000.000 (9)
var ONE_TRILLION    = 1000000000000;    // 1.000.000.000.000 (12)
var ONE_QUADRILLION = 1000000000000000; // 1.000.000.000.000.000 (15)
var MAX             = 9007199254740992; // 9.007.199.254.740.992

var lessThanTwenty = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 
    'ten', 'eleven', 'twelv', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen'];
var lessThanOneHundred = ['twenty', 'thirty', 'fourty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninty'];
var isFinite_ = Number.isFinite || function (value) {
    return typeof value === "number" && isFinite(value);
};

function numberWords(number) {
    return toWords(number);
}

var iterations = 0
function toWords(number, words) {
    if (!isFinite_(number)) throw TypeError;
    if (!words) words = [];
    iterations++;
    console.log(iterations, number, words);

    var remainder, currentWord;
    if (number === 0) {
        return words.join(' ');
        
    } else if (number < 20) {
        remainder = 0;
        currentWord = lessThanTwenty[number];
		
    } else if (number < ONE_HUNDRED) {
        remainder = number % TEN;
        currentWord = lessThanOneHundred[Math.floor(number / TEN)];
		
    } else if (number < ONE_THOUSAND) {
        remainder = number % ONE_HUNDRED;
        currentWord = toWords(Math.floor(number / ONE_HUNDRED)) + ' hundred';
		
    } else if (number < ONE_MILLION) {
        remainder = number % ONE_THOUSAND;
        currentWord = toWords(Math.floor(number / ONE_THOUSAND)) + ' thousand';
		
    } else if (number < ONE_BILLION) {
        remainder = number % ONE_MILLION;
        currentWord = toWords(Math.floor(number / ONE_MILLION)) + ' million';

    } else if (number < ONE_TRILLION) {
        remainder = number % ONE_BILLION;
        currentWord = toWords(Math.floor(number / ONE_BILLION)) + ' billion';
		
    } else if (number < ONE_QUADRILLION) {
        remainder = number % ONE_TRILLION;
        currentWord = toWords(Math.floor(number / ONE_TRILLION)) + ' trillion';
		
    } else if (number <= MAX) {
        remainder = number % ONE_QUADRILLION;
        currentWord = toWords(Math.floor(number / ONE_QUADRILLION)) + ' quadrillion';
		
    }
    
    words.push(currentWord);
    return toWords(remainder, words);
}

@@ -30,2675 +30,31 @@
 s = 
-numberWords;%0A%0A// TODO: Write tests - not 100%25 yet%0A// TODO: Minimize calls (MAX takes 32 calls)%0A// TODO: Add support for %E2%80%9Cst%E2%80%9D, %E2%80%9Cnd%E2%80%9D, %E2%80%9Crd%E2%80%9D and %E2%80%9Cth%E2%80%9D%0A%0Avar TEN             = 10;%0Avar ONE_HUNDRED     = 100;%0Avar ONE_THOUSAND    = 1000;             // 1.000 (3)%0Avar ONE_MILLION     = 1000000;          // 1.000.000 (6)%0Avar ONE_BILLION     = 1000000000;       // 1.000.000.000 (9)%0Avar ONE_TRILLION    = 1000000000000;    // 1.000.000.000.000 (12)%0Avar ONE_QUADRILLION = 1000000000000000; // 1.000.000.000.000.000 (15)%0Avar MAX             = 9007199254740992; // 9.007.199.254.740.992%0A%0Avar lessThanTwenty = %5B'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', %0A    'ten', 'eleven', 'twelv', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen'%5D;%0Avar lessThanOneHundred = %5B'twenty', 'thirty', 'fourty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninty'%5D;%0Avar isFinite_ = Number.isFinite %7C%7C function (value) %7B%0A    return typeof value === %22number%22 && isFinite(value);%0A%7D;%0A%0Afunction numberWords(number) %7B%0A    return toWords(number);%0A%7D%0A%0Avar iterations = 0%0Afunction toWords(number, words) %7B%0A    if (!isFinite_(number)) throw TypeError;%0A    if (!words) words = %5B%5D;%0A    iterations++;%0A    console.log(iterations, number, words);%0A%0A    var remainder, currentWord;%0A    if (number === 0) %7B%0A        return words.join(' ');%0A        %0A    %7D else if (number %3C 20) %7B%0A        remainder = 0;%0A        currentWord = lessThanTwenty%5Bnumber%5D;%0A%09%09%0A    %7D else if (number %3C ONE_HUNDRED) %7B%0A        remainder = number %25 TEN;%0A        currentWord = lessThanOneHundred%5BMath.floor(number / TEN)%5D;%0A%09%09%0A    %7D else if (number %3C ONE_THOUSAND) %7B%0A        remainder = number %25 ONE_HUNDRED;%0A        currentWord = toWords(Math.floor(number / ONE_HUNDRED)) + ' hundred';%0A%09%09%0A    %7D else if (number %3C ONE_MILLION) %7B%0A        remainder = number %25 ONE_THOUSAND;%0A        currentWord = toWords(Math.floor(number / ONE_THOUSAND)) + ' thousand';%0A%09%09%0A    %7D else if (number %3C ONE_BILLION) %7B%0A        remainder = number %25 ONE_MILLION;%0A        currentWord = toWords(Math.floor(number / ONE_MILLION)) + ' million';%0A%0A    %7D else if (number %3C ONE_TRILLION) %7B%0A        remainder = number %25 ONE_BILLION;%0A        currentWord = toWords(Math.floor(number / ONE_BILLION)) + ' billion';%0A%09%09%0A    %7D else if (number %3C ONE_QUADRILLION) %7B%0A        remainder = number %25 ONE_TRILLION;%0A        currentWord = toWords(Math.floor(number / ONE_TRILLION)) + ' trillion';%0A%09%09%0A    %7D else if (number %3C= MAX) %7B%0A        remainder = number %25 ONE_QUADRILLION;%0A        currentWord = toWords(Math.floor(number / ONE_QUADRILLION)) + ' quadrillion';%0A%09%09%0A    %7D%0A    %0A    words.push(currentWord);%0A    return toWords(remainder, words);%0A%7D
+require('./number-words');
 %0A

Update index.js