-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
55 lines (45 loc) · 1.46 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
class NumberAzeriTranslator {
teklik = ['', 'bir', 'iki', 'üç', 'dörd', 'beş', 'altı', 'yeddi', 'səkkiz', 'doqquz'];
onluq = ['', 'on', 'iyirmi', 'otuz', 'qırx', 'əlli', 'altmış', 'yetmiş', 'səksən', 'doxsan'];
yuzluk = ['', 'min', 'milyon', 'milyard', 'trilyon'];
constructor (number) {
this.number = number;
}
translate () {
let divider = 1;
const arr = [];
let number = this.number;
while (divider <= number) {
const remain = number % (divider * 10);
number -= remain;
arr.push(remain / (10 ** arr.length));
divider *= 10;
}
let index = 0;
let sentense = [];
while(arr.length) {
const triple = arr.splice(0, 3);
const result = this.getTripleString(triple);
if (result.length) {
sentense.push(this.getTripleString(triple) + ' ' + this.yuzluk[index]);
}
index++;
}
return sentense.reverse().join(' ');
}
getTripleString(triple) {
const arr = [];
const [teklik, onluq, yuzluk] = triple;
if (yuzluk) {
arr.push(`${this.teklik[yuzluk]} yüz`);
}
if (onluq) {
arr.push(`${this.onluq[onluq]}`);
}
if (teklik) {
arr.push(this.teklik[teklik]);
}
return arr.join(' ');
}
}
module.exports = NumberAzeriTranslator;