-
-
Save veloper/4155031 to your computer and use it in GitHub Desktop.
Which is more readable
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 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