So this is my code
stem = "/*smth*/"
for (var i = stem.length - 1; i >= 0; i--) {
if (stem[i] == 'ա' && stem[i-1] == 'ե' && stem[i+1] != undefined) {
var alternated = stem.slice(0, i) + stem.slice(i+1)
} else if (stem[i] == 'ե' && stem[i+1] == 'ւ' && stem[i+2] != undefined) {
var alternated = stem.slice(0, i) + "ի" + stem.slice(i+1)
} else if (stem[i] == 'ո' && stem[i+1] == 'յ' && stem[i+2] != undefined) {
var alternated = stem.slice(0, i+1) + "ւ" + stem.slice(i+2)
} else if (stem[i] == 'ո' && stem[i+1] == 'ւ' && stem[i+2] != undefined) {
var alternated = stem.slice(0, i) + stem.slice(i+2)
} else if (stem[i] == 'ի' && stem[i+1] != undefined) {
var alternated = stem.slice(0, i) + stem.slice(i+1)
} else if (stem[i] == 'է' && stem[i+1] != undefined) {
var alternated = stem.slice(0, i) + "ի" + stem.slice(i+1)
} else {
alternated = stem
}
}
alert(alternated)
It must change the stem
‘s value in some conditions and not to change in others and give the changed/not changed value to alternated
. But it doesn’t work, never change the stem
, else statement works everytime. If I delete else statement everything works great. I tried to write it with switch, it had the same problem, didn’t work with default:
and worked great without…