forked from rolling-scopes-school/human-readable-number
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
122 lines (122 loc) · 3.32 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
function numberChech (num){
const arrOne = [
'zero',
'one',
'two',
'three',
'four',
'five',
'six',
'seven',
'eight',
'nine',
'ten',
'eleven',
'twelve',
]
const arrTwo=[
'zero',
'one',
'twe',
'thir',
'four',
'fif',
'six',
'seven',
'eigh',
'nine',
]
const arrThree = [
'teen',
'ty',
'hundred',
'thousand',
]
if (num<13){
return(`${arrOne[num]}`)
}else if(num<20){
let a = num -10
return(`${arrTwo[a]}${arrThree[0]}`)
}else if(num<100){
let a = Math.trunc(num*0.1)
let b = num-(a*10)
return(`${arrTwo[a]}${arrThree[1]} ${arrOne[b]}`)
}else if (num<1000){
let a = Math.trunc(num*0.01)
let b = Math.trunc((num-(a*100))*0.1)
let c = num-(Math.trunc(num*0.1))*10
let d=String(b)+String(c)
if (d<13){
d=arrOne[d]
return(`${arrOne[a]} ${arrThree[2]} and ${d}`)
}else if (d<20){
d = `${arrTwo[d-10]}${arrThree[0]}`
return(`${arrOne[a]} ${arrThree[2]} and ${d}`)
}else{
return(`${arrOne[a]} ${arrThree[2]} and ${arrTwo[b]}${arrThree[1]} ${arrOne[c]}`)
}
}else if(num<10000){
let e = Math.trunc(num*0.001)
let a = Math.trunc(num*0.01)-(e*10)
let b = Math.trunc((num-e*1000-a*100)*0.1)
let c = num-(Math.trunc(num*0.1))*10
let d=String(b)+String(c)
if (d<13){
d=arrOne[d]
return(`${arrOne[e]} ${arrThree[3]} ${arrOne[a]} ${arrThree[2]} and ${d}`)
}else if (d<20){
d = `${arrTwo[d-10]}${arrThree[0]}`
return(`${arrOne[e]} ${arrThree[3]} ${arrOne[a]} ${arrThree[2]} and ${d}`)
}else{
return(`${arrOne[e]} ${arrThree[3]} ${arrOne[a]} ${arrThree[2]} and ${arrTwo[b]}${arrThree[1]} ${arrOne[c]}`)
}
}else if (num<100000){
let k = Math.trunc(num*0.0001)
let e = Math.trunc(num*0.001)-(k*10)
let a = Math.trunc(num*0.01)-(k*100)-(e*10)
let b = Math.trunc(num*0.1)-(k*1000)-(e*100)-(a*10)
let c = num-(Math.trunc(num*0.1))*10
let d = String(b)+String(c)
let l = String(k)+String(e)
if (l<13){
l = `${arrOne[l]}`
}else if (l<20){
l=`${arrTwo[l-10]}${arrThree[0]}`
}else{
l=`${arrTwo[k]}${arrThree[1]} ${arrOne[e]}`
}
if (d<13){
d=arrOne[d]
return(`${l} ${arrThree[3]} ${arrOne[a]} ${arrThree[2]} and ${d}`)
}else if (d<20){
d = `${arrTwo[d-10]}${arrThree[0]}`
return(`${l} ${arrThree[3]} ${arrOne[a]} ${arrThree[2]} and ${d}`)
}else{
return(`${l} ${arrThree[3]} ${arrOne[a]} ${arrThree[2]} and ${arrTwo[b]}${arrThree[1]} ${arrOne[c]}`)
}
}else if (num<1000000){
let m = Math.trunc(num*0.00001)
let k = Math.trunc(num*0.0001)-(m*10)
let e = Math.trunc(num*0.001)-(k*10) - (m*100)
let a = Math.trunc(num*0.01)-(e*10)-(k*100)-(m*1000)
let b = Math.trunc(num*0.1)-(a*10)-(e*100)-(k*1000)-(m*10000)
let c = num-(Math.trunc(num*0.1))*10
let d = String(b)+String(c)
let l = String(k)+String(e)
if (l<13){
l = `${arrOne[l]}`
}else if (l<20){
l=`${arrTwo[l-10]}${arrThree[0]}`
}else{
l=`${arrTwo[k]}${arrThree[1]} ${arrOne[e]}`
}
if (d<13){
d=arrOne[d]
return(`${arrOne[m]} ${arrThree[2]} and ${l} ${arrThree[3]} ${arrOne[a]} ${arrThree[2]} and ${d}`)
}else if (d<20){
d = `${arrTwo[d-10]}${arrThree[0]}`
return(`${arrOne[m]} ${arrThree[2]} and ${l} ${arrThree[3]} ${arrOne[a]} ${arrThree[2]} and ${d}`)
}else{
return(`${arrOne[m]} ${arrThree[2]} and ${l} ${arrThree[3]} ${arrOne[a]} ${arrThree[2]} and ${arrTwo[b]}${arrThree[1]} ${arrOne[c]}`)
}
}}