DEV Community

Cover image for Codewars - Disemvowel Trolls
Nicolás Bost
Nicolás Bost

Posted on

Codewars - Disemvowel Trolls

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;
}
Enter fullscreen mode Exit fullscreen mode

But what code?

Dain bramage

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;
}
Enter fullscreen mode Exit fullscreen mode

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;
}
Enter fullscreen mode Exit fullscreen mode

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 💧💧💧.

SurveyJS custom survey software

JavaScript UI Libraries for Surveys and Forms

SurveyJS lets you build a JSON-based form management system that integrates with any backend, giving you full control over your data and no user limits. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more.

Learn more

Top comments (0)

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay