Having array like this
[
{:id=>2, :idx=>111, :money=>4, :money1=>1, :order=>“001”,
:order1=>“1”},
{:id=>1, :idx=>112, :money=>2, :money1=>2, :order=>“001”,
:order1=>“1”},
{:id=>3, :idx=>113, :money=>3, :money1=>1, :order=>“002”,
:order1=>“2”}
]
After calling method: f_addition(arr, group_fields, sum_fields,
max_fields) (e.x: f_addition(arr, [:order, :order1], [:money, :money1],
[:id, :idx] ). If groups_fields = [], meaning sum all fields in
sum_fields
The result should be:
[
{:id=>2, :idx=>112, :money=>6, :money1=>3,:order=>“001”,
:order1=>“1”},
{:id=>3, idx=>113, :money=>3, ":money1=>1,:order=>“002”,
:order1=>“2”}
]
P/s: the original array should not be changed after calling method (it
is used again as parameter for new group_fields, new sum_fields, new
max_fields)
I am using Ruby 1.8.7 and Rails 2.3.5
Please teach me how to build the method f_addition.
Thanks