Home > Web Front-end > JS Tutorial > Codewars - Disemvowel Trolls

Codewars - Disemvowel Trolls

Linda Hamilton
Release: 2025-01-02 15:58:38
Original
190 people have browsed it

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;
}
Copy after login

But what code?

Codewars - Disemvowel Trolls

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;
}
Copy after login

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;
}
Copy after login

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

The above is the detailed content of Codewars - Disemvowel Trolls. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template