JSFiddle - React, Tailwind, and code Playground
by Chase Wilson
HTML
<!--
describe("textifyInt", function() {
it("1 should return ones", function() {
numberLetter(1).should.equal("one");
});
it("12 should return twelve", function() {
numberLetter(12).should.equal("twelve");
});
});
-->
CSS
the one will run through but nt the 12
JavaScript
var ones = ["zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sisteen","seventeen","eightteen","nineteen"]
var tens = ["","ten","twenty","thirty","fourty","fifty","sixty","seventy","eighty","ninety"]
var blegh = {3: "hundred",4:"hundred",5:"thousand",6:"thousand",7:"million"} // etc
// Stolen from http://stackoverflow.com/questions/10073699/pad-a-number-with-leading-zeros-in-javascript
function zeroPad(n, width, z) {
z = z || '0';
n = n + '';
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
}
function getLast(num, numbers) {
var str = String(numbers)
// capture the last two characters
return zeroPad(str.substr(str.length - num, str.length), num)
}
function textifyInt (num) {}
function arrayifyInt (num) {}
function parseHundreds (num) {
// number to a string
var str = getLast(3, num);
return ( str[0] == '0' ) ? parseTens(num) : (parseOnes(str[0]) +' hundred '+ parseTens(num)).trim();
}
// We only look at the last two integers
// all others are ignored.
function parseTens (num) {
// number to a string
var str = getLast(2, num);
return (str[0] == "1")? ones[num] : tens[str[0]] + ' ' + parseOnes(str[1]);
}
function parseOnes (num) {
var str = getLast(1, num);
return (num && ones[str]) ? ones[str]:'';
}