Skip to content
This repository was archived by the owner on Jun 8, 2019. It is now read-only.

Conversation

@brozturk
Copy link

@brozturk brozturk commented Dec 5, 2013

No description provided.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can avoid the nested loops by using repeated_permutation, which will give you exactly the same combinations of n and x as nesting each.

[1, 4, 7].repeated_permutation(2).each do |n, x|
  subgrids << subgrid(n, x)
end

If you combine that with map you can also remove both the first and the last lines of the method.

[1, 4, 7].repeated_permutation(2).map do |n, x|
  subgrid(n, x)
end

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants