add transpose methods
This commit is contained in:
parent
c9d74589d9
commit
1616abeb6a
2 changed files with 19 additions and 0 deletions
9
lib/enum_util.ex
Normal file
9
lib/enum_util.ex
Normal file
|
@ -0,0 +1,9 @@
|
|||
defmodule EnumUtil do
|
||||
def transpose(enum) do
|
||||
col_count = enum |> Enum.at(0) |> Enum.count()
|
||||
|
||||
for col <- 0..(col_count - 1) do
|
||||
enum |> Enum.map(&Enum.at(&1, col))
|
||||
end
|
||||
end
|
||||
end
|
10
lib/string_util.ex
Normal file
10
lib/string_util.ex
Normal file
|
@ -0,0 +1,10 @@
|
|||
defmodule StringUtil do
|
||||
def transpose(str) do
|
||||
EnumUtil.transpose(
|
||||
str
|
||||
|> String.split("\n")
|
||||
|> Enum.map(&String.graphemes(&1))
|
||||
|
||||
)|> Enum.map(&Enum.join(&1,"")) |> Enum.join("\n")
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue