0
Sortierung ich einige Probleme mit versuchen, eine Liste von Strukturen in Elixir zu sortieren ...Elixir Enum.sort nicht richtig
Ich kann nicht herausfinden, was ich falsch mache.
IO.puts "########### MY TOP 5 #############"
IO.inspect mytop5
IO.puts "================================="
sorted = Enum.sort_by(mytop5, &(&1.count))
IO.inspect sorted
IO.puts "------------------------"
Hier ist das Ergebnis
iex(67)> ########### MY TOP 5 #############
iex(67)> [%{count: "3", from: "AUD", rate: 0.64536947, to: "EUR"},
%{count: "10", from: "USD", rate: 1.3876, to: "AUD"},
%{count: "11", from: "USD", rate: 0.89726335, to: "EUR"}]
iex(67)> =================================
iex(67)> [%{count: "3", from: "AUD", rate: 0.64536947, to: "EUR"},
%{count: "11", from: "USD", rate: 0.89726335, to: "EUR"},
%{count: "10", from: "USD", rate: 1.3876, to: "AUD"}]
iex(67)> ------------------------
während:
iex(3)> [%{plop: "aze", count: 5, name: "a"}, %{plop: "aze", count: 1, name: "p"}, %{plop: "aze", count: 45, name: "e"}] |> Enum.sort_by(&(&1.count))
[%{count: 1, name: "p", plop: "aze"}, %{count: 5, name: "a", plop: "aze"},
%{count: 45, name: "e", plop: "aze"}]
Verdammt, ich auf die Tatsache nicht einmal bezahlt haben Aufmerksamkeit, die es ein String und kein Integer war! Danke. +1 – TheSquad