loading...

Daily Challenge #148 - Disemvowel Trolls

thepracticaldev profile image dev.to staff ・1 min read

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!

Discussion

pic
Editor guide
Collapse
andreasjakof profile image
Andreas Jakof

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
Collapse
jaimesanchezm4 profile image
Jaime Sánchez M.

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

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
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
kasem007 profile image
Kasem007

Liquid syntax error: Unknown tag 'def'

Collapse
yechielk profile image
Yechiel Kalmenson

Ruby:

def disemvowel(string)
    string.gsub(/[aeiou]/i, "")
end
Collapse
rafaacioly profile image
Rafael Acioly

Python solution 🐍

import re

VOWELS_REGEX = r"[aeiou]"

def removeVowels(message: str) -> str:
  return re.sub(VOWELS_REGEX, '', message, flags=re.IGNORECASE)
Collapse
fitsum profile image
fitsum

JS

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