-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathordinal.js
47 lines (44 loc) · 892 Bytes
/
ordinal.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
const _ithMap = {
1: 'first',
2: 'second',
3: 'third',
4: 'fourth',
5: 'fifth',
6: 'sixth',
7: 'seventh',
8: 'eigth',
9: 'ninth',
10: 'tenth',
11: 'eleventh',
12: 'twelfth',
13: 'thirteenth',
14: 'fourteenth',
15: 'fifteenth',
16: 'sixteenth',
17: 'seventeenth',
18: 'eighteenth',
19: 'nineteenth',
20: 'twentieth',
30: 'thirtieth',
40: 'fourtieth',
50: 'fiftieth',
60: 'sixtieth',
70: 'seventieth',
80: 'eightieth',
90: 'ninetieth'
};
module.exports = {
translate(num) {
if (typeof num !== 'number') {
throw new Error('ordinal.translate [argument num is not a number]');
}
const intNum = parseInt(num);
if (intNum <= 0) {
return 'Negative numbers are not supported';
}
else if (intNum > 20) {
return 'Numbers greater than 20 are not yet supported';
}
return _ithMap[intNum];
}
};