Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trying to fix #28

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 85 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,86 @@
module.exports = function toReadable (number) {


module.exports = function toReadable (num) {

const arrUnits = ['', 'one', 'two', 'three', 'four', 'five',
'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen',
'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen', 'twenty'];

const arrDozens = ['', 'one', 'twenty', 'thirty', 'forty', 'fifty',
'sixty', 'seventy', 'eighty', 'ninety'];

const arrHundred = ['', 'one hundred', 'two hundred', 'three hundred', 'four hundred', 'five hundred',
'six hundred', 'seven hundred', 'eight hundred', 'nine hundred'];

const arrThousen = ['', 'one thousand', 'two thousand', 'three thousand', 'four thousand', 'five thousand',
'six thousand', 'seven thousand', 'eight thousand', 'nine thousand'];

const arrMillions = ['', 'one million', 'two millions', 'three millions', 'four millions', 'five millions',
'six millions', 'seven millions', 'eight millions', 'nine millions', 'ten millions', 'eleven millions', 'twelve millions', 'thirteen millions',
'fourteen millions', 'fifteen millions', 'sixteen millions', 'seventeen millions', 'eighteen millions', 'nineteen millions', 'twenty millions'];

function numty(num) {

let numStr = String(num);
// console.log ('numStr length is ' + numStr.length)

let unitsDozens = +(numStr.slice(-2));
// console.log('units dozens is ' + unitsDozens)
let units = +(numStr.slice(-1));
// console.log('units is ' + units)
let dozens = +(numStr.slice(-2, -1));
// console.log('dozens is ' + dozens)
let hundred = +(numStr.slice(-3, -2));
// console.log('hundred is ' + hundred)

// let thousand = +(numStr.slice(-4, -3));
// console.log('thousand is ' + thousand)
// let tenThousen = +(numStr.slice(-5, -4));
// console.log('ten thousand is ' + thousand)
// let combTenThousen = +(numStr.slice(-5,-3));
//console.log (combTenThousen)
// let millions = +(numStr.slice(-6,-5));
//console.log (arrMillions)

function comby(unitsDozens) {
if (unitsDozens == 00) {
return `${''}`
} else if (unitsDozens > 20 && unitsDozens <= 99) {
return `${arrDozens[dozens]}${' '}${arrUnits[units]}`;
} else if (unitsDozens <= 20) {
return `${arrUnits[unitsDozens]}`
}

// console.log (comby('unitsdozens is true' + unitsDozens))
}
// console.log ('number is ' + num)

let combySwitch = `${' '}${comby(unitsDozens)}`;

let combySwitchDozensUnits = `${arrDozens[dozens]}`;

(unitsDozens == 00) ? (combySwitch = '') : combySwitch;

(units == 0) ? (combySwitchDozensUnits) : combySwitchDozensUnits = (`${comby(unitsDozens)}`);

switch(numStr.length){
case 2:
return `${combySwitchDozensUnits}`
break;
case 3:
return `${arrHundred[hundred]}${combySwitch}`
break;
case 4:
// return `${arrThousen[thousand]}${' '}${arrHundred[hundred]}${comby(unitsDozens)}`
// break;
// case 5:
// return `${arrDozens[tenThousen]}${arrThousen[thousand]}${arrHundred[hundred]}${comby(unitsDozens)}`
// break;
// case 6:
// return `${arrHundred[hundred]}${arrDozens[tenThousen]}${arrThousen[thousand]}${arrHundred[hundred]}${comby(unitsDozens)}`
// break;

}
}

return (numty(num))
}