Created
January 11, 2023 11:21
-
-
Save TwistingTwists/50c55c0de147e82511350acb8fad1b4b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Username do | |
def sanitize(username) do | |
# ä becomes ae | |
# ö becomes oe | |
# ü becomes ue | |
# ß becomes ss | |
for u <- username do | |
case u do | |
# _ | |
?_ -> '_' | |
# \s | |
# ?\s -> nil | |
# ü | |
?ü -> 'ue' | |
# ö | |
?ö -> 'oe' | |
# ä | |
?ä -> 'ae' | |
# ß | |
?ß -> 'ss' | |
a when a <= ?z and a >= ?a -> [a] | |
# a when (a >= ?0 and a <= ?9) -> nil | |
_ -> '' | |
end | |
end | |
# |> Enum.filter( | |
# fn entry -> entry != nil end | |
# ) | |
|> List.flatten() | |
# Please implement the sanitize/1 function | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment