function magic(s) {
let v = ["a", "e", "i", "o", "u"];
let r = "";
for (let i = 0; i < s.length; i++) {
if (v.includes(s[i])) r += s[i].toUpperCase();
else r += s[i];
}
r = r.split("").reverse();
if (!v.includes(r[r.length])) r.pop();
return r.join("-");
}
console.log(magic("hellothere")); // E-r-E-h-t-O-l-l-E
ZnVuY3Rpb24gbWFnaWMocykgewogIGxldCB2ID0gWyJhIiwgImUiLCAiaSIsICJvIiwgInUiXTsKICBsZXQgciA9ICIiOwoKICBmb3IgKGxldCBpID0gMDsgaSA8IHMubGVuZ3RoOyBpKyspIHsKICAgIGlmICh2LmluY2x1ZGVzKHNbaV0pKSByICs9IHNbaV0udG9VcHBlckNhc2UoKTsKICAgIGVsc2UgciArPSBzW2ldOwogIH0KCiAgciA9IHIuc3BsaXQoIiIpLnJldmVyc2UoKTsKICBpZiAoIXYuaW5jbHVkZXMocltyLmxlbmd0aF0pKSByLnBvcCgpOwoKICByZXR1cm4gci5qb2luKCItIik7Cn0KCmNvbnNvbGUubG9nKG1hZ2ljKCJoZWxsb3RoZXJlIikpOyAvLyBFLXItRS1oLXQtTy1sLWwtRQ==