Last active
September 13, 2020 00:18
-
-
Save adworse/4c4f7f775d19fe9d89ddda906ab265de 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 LessNaive do | |
def trim_string(string) do | |
string | |
|> String.graphemes() | |
|> Enum.reduce_while("", fn grapheme, acc -> | |
if counter(acc <> grapheme) <= 80, | |
do: {:cont, acc <> grapheme}, | |
else: {:halt, acc} | |
end) | |
end | |
defp counter(string), do: string |> String.codepoints |> Enum.count | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment