Somebody wrote this (very terrible) function to translate a numeric value from 0-999 to English words.
function getNumberWords(number) {
var list = new Array(1000);
list[000] = "zero";
list[001] = "one";
list[002] = "two";
list[003] = "three";
///skip a few
list[099] = "ninety nine";
list[100] = "one hundred";
list[101] = "one hundred and one";
///skip a few more
list[997] = "nine hundred and ninety seven";
list[998] = "nine hundred and ninety eight";
list[999] = "nine hundred and ninety nine";
return list[number];
}
There is some rather odd bug in here that I can't seem to figure out the cause of. Some, but not all of the elements are placed in the wrong cell.
I tried displaying the contentes of the list and it showed a pretty funky result:
> list.toString();
"zero,one,two,three,four,five,six,seven,ten,eleven,twelve,thirteen,fourteen,
fifteen,sixteen,seventeen,twenty,twenty one,twenty two,twenty three,twenty four,
twenty five,twenty six,twenty seven,thirty,thirty one,thirty two,thirty three,
thirty four,thirty five,thirty six,thirty seven,forty,forty one,forty two,"
///(skip a few)
"sixty six,sixty seven,seventy,seventy one,seventy two,seventy three,seventy four,
seventy five,seventy six,seventy seven,,,,,sixty eight,sixty nine,,,,,,,,,
seventy eight,seventy nine,eighty,eighty one,eighty two,eighty three,eighty four,"
///(and so on)
That is, elements 0-7 have the expected value. Elements 68, 69, and 78-999 also have the expected values. Elements 64-67 and 70-77 are empty. Elements 8-63 have incorrect values.
What in the world is going on here? Why are 15 cells empty, 56 cells incorrect, and the rest correct?