Created
November 27, 2012 15:35
-
-
Save ss-kelsmj/4154851 to your computer and use it in GitHub Desktop.
Which is more readable
This file contains hidden or 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 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) | |
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 | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment