Created
September 21, 2017 13:24
-
-
Save dav11d/7249097935102cc2a9b5adc4d1eb4b19 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def atc([], new_item) do | |
[new_item] | |
end | |
def atc([h = %{product_id: id, size: size, quantity: old_quantity}|t], %{product_id: id, quantity: growth, size: size}) do | |
[%{h | quantity: old_quantity + growth}|t] | |
end | |
def atc([h|t], new_item) do | |
[h|atc(t, new_item)] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment