Fun way to start a coding experience.
Oh no. Trolls took the comment section by storm. We need to do something. Hiring mods requires money, apparently, so instead we are tasked with altering the comment. Why? No idea, just do it:
function disemvowel(str) {
// your code here
return str;
}
But what code?
Becoming friends with documentation is essential to avoid double homework. MDN to the rescue. The function alters the string passed in. This is the result:
function disemvowel(str) {
str = str.replaceAll(/[aeiouAEIOU]/, "");
return str;
}
Wait. It doesn't work. But why? The syntax is correct, right?
Kinda. It's missing one key element. The g
flag.
What is that and why it exists? I would like to know as well. Unfortunately, all I can say is experts implemented it this way, and it works.
Corrected:
function disemvowel(str) {
str = str.replaceAll(/[aeiouAEIOU]/g, "");
return str;
}
Not the best, nor the simplest solution. Would like to know how to benchmark code the right way. But that's for another time.
'Til next time. Drink water 💧💧💧.
Top comments (0)