I would define DECADES[0]
as "" instead of "zero" so that the if (tens>0)
can be removed. Notice that DECADES[0]
was never used and its value "zero" was a repetition with respect to SUBTWENTY[0]
.
Also there is a repetition in the creation of the "subhundred" part of the number.
In fact you can safely remove this part of code:
if (value < SUBTWENTY.length) {
return SUBTWENTY[value];
}
which is anyway correctly handled by the code following.