Last active
August 29, 2015 14:02
-
-
Save danielfone/091cd5ac788ec446faa4 to your computer and use it in GitHub Desktop.
Iterate over multiple arrays
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
x_coords = [...] | |
y_coords = [...] | |
x_coords.each do |x| | |
y_coords.each do |y| | |
do_point x, y | |
end | |
end |
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
x_coords = [...] | |
y_coords = [...] | |
x_coords.product(y_coords).each do |x, y| | |
do_point x, y | |
end | |
# edit even better: | |
points = x_coords.product y_coords | |
points.each do |x, y| | |
do_point x, y | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i'd prefer the second. language features are there to be used.
and if this can be optimized then it is more likely that a builtin .product gets optimized than the parser detecting that a nested .each can be optimized.
greetings, eMBee