Skip to content

Instantly share code, notes, and snippets.

@veloper
Forked from ss-kelsmj/gist:4154851
Created November 27, 2012 15:57
Show Gist options
  • Save veloper/4155031 to your computer and use it in GitHub Desktop.
Save veloper/4155031 to your computer and use it in GitHub Desktop.
Which is more readable
def sum_data(index, page, data)
t = []
page.each do |p|
if t.length == 0
t = get_data_array(p, index, data)
else
temp = get_data_array(p, index, data)
t.each_index do | i |
t[i] += temp[i]
end
end
end
t
end
def sum_data(index, page, data)
page.reduce(get_data_array(p, index, data)) do |seed, p|
temp = get_data_array(p, index, data)
seed.each_index { |i| seed[i] += temp[i] }
seed
end
end
def sum_data(index, page, data)
t = []
page.each do |p|
t = get_data_array(p, index, data).zip(t).collect { |x| x.flatten().inject{|sum,x| sum + x.to_i }}
end
t
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment