I have a pretty straight-forward problem, but struggle to make it clear and concise (is that possible at all!?).
So having two lists:
list_1 = ["$100", "$200", "$300"]
list_2 = ["bob", "$200", "sam"]
success output should be:
"bob: $100, sam: $300"
fail output:
list_1 = ["$100", "$200", "$300"]
list_2 = ["bob", "bob", "sam"]
false
Obviously, list_2
(or our pattern) might be different, but if prices are matching we should return a success output similar to above.
I approached it right away by:
iex(2)> Enum.zip(["bob", "$200", "sam"], ["$100", "$200", "$300"])
[{"bob", "$100"}, {"$200", "$200"}, {"sam", "$300"}]
and then with a lot of conditional logic and accumulators in Enum.reduce solved the problem, but it’s super ugly… When my Elixir code is ugly - I’m always questioning myself, since there is always another and cleaner way.
How would you approach this? Is there a way?
Thank you all in advance!