Last active
May 16, 2022 20:54
-
-
Save girorme/9c662a2a2e4efc1653881f0115928f11 to your computer and use it in GitHub Desktop.
tdd livebook
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 Solution do | |
def remove_duplicate_chars(string) do | |
string | |
|> String.codepoints() | |
|> Enum.reduce(fn char, acc -> | |
acc = if String.contains?(acc, char) do | |
acc | |
else | |
acc <> char | |
end | |
end) | |
end | |
end |
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
ExUnit.start(auto_run: false) | |
defmodule SolutionTest do | |
use ExUnit.Case, async: false | |
describe "Testing remove duplicate chars" do | |
test "remove a from aaabc" do | |
assert Solution.remove_duplicate_chars("aaabc") === "abc" | |
end | |
end | |
end | |
ExUnit.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment