How to get min values structs from array?

I think peerreynders gave the most professional answer.

You can use this function,

  def getmin(maplst, key) do
    m = maplst |> Enum.map(fn(x) -> Map.get(x, key) end) |> Enum.min
    Enum.filter(maplst, fn(x) -> Map.get(x, key) == m end)
  end

in your case put in your

array = [%{count: 1, img: 1}, %{count: 1, img: 2}, %{count: 3, img: 3}, %{count: 1, img: 4}]

and :count as arguments and it should work.

I’m sure there’s a more elegant way to solve your problem, this is just what I came up with.