DEV Community

dev.to staff
dev.to staff

Posted on

7 1

Daily Challenge #148 - Disemvowel Trolls

Setup
Trolls are invading the comment section!

To deal with the threat, write a function that takes a string and returns a new string with all vowels removed (y not included).

Example
"This website is for losers LOL!" => "Ths wbst s fr lsrs LL"

Tests
"No newbies allowed, go to #beginners" =>
"LULZ TROLLED" =>

Try to keep it simple. Have fun!


This challenge comes from osuushi on CodeWars. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!

Want to propose a challenge idea for a future post? Email yo+challenge@dev.to with your suggestions!

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (15)

Collapse
 
andreasjakof profile image
Andreas Jakof • Edited

In C#

public static readonly List<Char> LowerCaseVowels = new List<Char> {'a', 'e', 'i', 'o', 'u'};

public static bool IsLowerCaseVowel(this char c) => LowerCaseVowels.Contains(c);

public static string RemoveVowels(string input) =>
    new string(input.Where(c => !c.ToLowerInvariant().IsLowerCaseVowel()));
Collapse
 
praneetnadkar profile image
Praneet Nadkar

Or may be just

var cleaned = Regex.Replace(input,"[aeiou]", "", RegexOptions.IgnoreCase);

Collapse
 
andreasjakof profile image
Andreas Jakof

Nice One!

Collapse
 
jaimesanchezm4 profile image
Jaime Sánchez M. • Edited

In Ts:

const removeVowels = (text: string) => text.replace(/[aeiou]/gi, '');
Collapse
 
ultrainstinct05 profile image
Ashwin Shenoy

Python solution.

def disemvowel(string):
    """Removes all occurences of vowel from the string.

    Args:
        string (str): The input string.

    Returns:
        temp_string (str): The resultant string with vowels removed.
    """
    final_string = ""
    for i in string:
        if i.lower() in ["a", "e", "i", "o", "u"]:
            continue
        else:
            final_string += i
    return final_string

if __name__ == '__main__':
    print(disemvowel("This website is for losers LOL!"), "Ths wbst s fr lsrs LL!")
Collapse
 
rafaacioly profile image
Rafael Acioly

you could use regex to keep it simple :)

Collapse
 
ultrainstinct05 profile image
Ashwin Shenoy

I am yet to study about regexes :)

Collapse
 
rburmorrison profile image
Ryan Burmeister-Morrison • Edited

Here's a Ruby submission!

# Remove all vowels ('y' not included) from a string.
#
# @param [String] the string to strip vowels from
#
# @return [String] the resulting string
def disemvowel(str)
  str.split('').select { |ch| !ch.match(/^[aeiou]$/i) }.join('')
end

puts disemvowel("This website is for losers LOL!")
puts disemvowel("No newbies allowed, go to #beginners")
puts disemvowel("LULZ TROLLED")

Here's a link to the Repl.it: repl.it/@rburmorrison/DevToChallen...

Collapse
 
bamartindev profile image
Brett Martin

Standard ML of New Jersey Solution


val vowels = [#"a", #"e", #"i", #"o", #"u"]
fun member_of (item, list) = List.exists (fn x => x = item) list
fun disemvowel s = implode (List.filter (fn x => not(member_of(Char.toLower x, vowels))) (explode s))

Collapse
 
aminnairi profile image
Amin

Elm

module Main exposing (main)

import Char exposing (toLower)
import List exposing (member)
import String exposing (filter)


isForbiddenInsensitive : List Char -> Char -> Bool
isForbiddenInsensitive characterList character =
    member (toLower character) characterList


removeVowels : String -> String
removeVowels =
    filter <| not << isForbiddenInsensitive [ 'a', 'e', 'i', 'o', 'u' ]

Example.

Collapse
 
kasem777 profile image
Kasem777 • Edited

Liquid syntax error: Unknown tag 'def'

Collapse
 
yechielk profile image
Yechiel Kalmenson • Edited

Ruby:

def disemvowel(string)
    string.gsub(/[aeiou]/i, "")
end
Collapse
 
kmruiz profile image
Kevin Mas Ruiz

Some unfancy Common Lisp:

(defun remove-vowels (text)
  (flet ((vowel-p (char) (find char "aeiouAEIOU" :test #'char=)))
    (remove-if #'vowel-p text)))
Collapse
 
fitsum profile image
fitsum • Edited

JS

const disemvowel = (str) => str.replace(/[aeoiu]/gi, '');

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

👋 Kindness is contagious

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

Okay