-
Notifications
You must be signed in to change notification settings - Fork 1
/
convertToOrdinal.js
46 lines (39 loc) · 1.17 KB
/
convertToOrdinal.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
var SUFFIX = {"frontNonRounded":'inci', "frontRounded":'üncü', "backNonRounded":'ıncı',"backRounded" :'uncu'};
var frontNonRounded = ['i','e','ə'];
var frontRounded = ['ü','ö'];
var backNonRounded = ['a','ı'];
var backRounded = ['u','o'];
var vowels = frontNonRounded.concat(frontRounded,backRounded,backNonRounded);
var suffix = '';
function convertToOrdinal(text){
if(text == "sıfır"){
return "sıfrıncı";
}
var lastWord = text.split(' ').splice(-1).join('');
var vowel = '';
var reversed = lastWord.split('').reverse().join('');
for(i = 0;i < reversed.length; i++){
if(vowels.includes(reversed.charAt(i))){
vowel = reversed.charAt(i);
break;
}
}
if(frontNonRounded.includes(vowel)){
suffix = SUFFIX.frontNonRounded;
}
else if(frontRounded.includes(vowel)){
suffix = SUFFIX.frontRounded;
}
else if(backRounded.includes(vowel)){
suffix = SUFFIX.backRounded;
}
else if(backNonRounded.includes(vowel)){
suffix = SUFFIX.backNonRounded;
}
if(reversed.charAt(0) == suffix.charAt(0)){
suffix = suffix.substr(1);
}
var ordinal = text += suffix;
console.log(ordinal);
}
convertToOrdinal('on min bir')