Anonymous user
Align columns: Difference between revisions
→{{header|Elixir}}: String.ljust -> pad_trailing
(→{{header|Elixir}}: String.ljust -> pad_trailing) |
|||
Line 1,592:
=={{header|Elixir}}==
{{trans|Ruby}}
{{works with|Elixir|1.3}}
The String module of Elixir doesn't have the function of the center position adjusting.
It calls and processes the function of 'Erlang'.
Line 1,597 ⟶ 1,598:
def columns(text, alignment) do
fieldsbyrow = String.split(text, "\n", trim: true)
|> Enum.map(fn
maxfields = Enum.map(fieldsbyrow, fn field -> length(field) end) |> Enum.max
colwidths = Enum.map(fieldsbyrow, fn field -> field ++ List.duplicate("", maxfields - length(field)) end)
Line 1,611 ⟶ 1,612:
end
defp adjust(field, width, :Left), do: String.
defp adjust(field, width, :Right), do: String.
defp adjust(field, width, _), do: :string.centre(String.
end
|