Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for [old] Speech Module by Sim0000
"use strict";
const FIRST_TEN = ["one", "two", "three", "four", "five", "six", "seven",
"eight", "nine"],
SECOND_TEN = ["ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen",
"sixteen", "seventeen", "eighteen", "nineteen"],
OTHER_TENS = ["twenty", "thirty", "forty", "fifty", "sixty", "seventy",
"eighty", "ninety"],
HUNDRED = "hundred";
function speechModule(number){
let n = Math.floor(number / 100);
let result = n ? [FIRST_TEN[n - 1], HUNDRED] : [];
n = Math.floor(number / 10) % 10;
if(n > 1) result.push(OTHER_TENS[n - 2]);
n = number % (n > 1 ? 10 : 20);
if(n) result.push((FIRST_TEN.concat(SECOND_TEN))[n - 1]);
return number ? result.join(' ') : 'zero';
}
var assert = require('assert');
if (!global.is_checking) {
assert.equal(speechModule(4), 'four', "four");
assert.equal(speechModule(133), 'one hundred thirty three', "one hundred thirty three");
assert.equal(speechModule(12), 'twelve', "twelve");
assert.equal(speechModule(101), 'one hundred one', "one hundred one");
assert.equal(speechModule(212), 'two hundred twelve', "two hundred twelve");
assert.equal(speechModule(40), 'forty', "forty");
console.log("Done! Go and Check IT!");
}
July 29, 2017
Comments: