Skip to content

Instantly share code, notes, and snippets.

@adworse
Last active September 13, 2020 00:18
Show Gist options
  • Save adworse/4c4f7f775d19fe9d89ddda906ab265de to your computer and use it in GitHub Desktop.
Save adworse/4c4f7f775d19fe9d89ddda906ab265de to your computer and use it in GitHub Desktop.
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