function myReplace(str, before, after) {
if (before[0] === before[0].toUpperCase()) {
after = after.replace(after[0], after[0].toUpperCase());
}
return str.replace(before, after);
}
function myToUpperCase(str) {
var newStr = '';
for (var i=0;i<str.length;i++) {
var thisCharCode = str[i].charCodeAt(0);
if ((thisCharCode>=97 && thisCharCode<=122)||(thisCharCode>=224 && thisCharCode<=255)) {
newStr += String.fromCharCode(thisCharCode - 32);
} else {
newStr += str[i];
}
}
return newStr;
}
console.log(myToUpperCase('helLo woRld!')); // => HELLO WORLD!
console.log(myToUpperCase('üñïçødê')); // => ÜÑÏÇØDÊ