Is there a transpose function in Elixir? -
hi transpose function in elixir. example have kind of array 'a' , after calling function result should 'b':
a = [[1, 2], [3, 4], [5, 6]] b = transpose(a) b => [[1, 3, 5], [2, 4, 6]]
there isn't 1 in elixir currently, create own with:
def transpose([]), do: [] def transpose([[]|_]), do: [] def transpose(a) [enum.map(a, &hd/1) | transpose(enum.map(a, &tl/1))] end
Comments
Post a Comment