Skip to content

Instantly share code, notes, and snippets.

@owainlewis
Created April 28, 2012 23:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save owainlewis/2522644 to your computer and use it in GitHub Desktop.
Save owainlewis/2522644 to your computer and use it in GitHub Desktop.
Grouping sequence by n in Ruby
def group_sequence_by n, sequence
Array.new.tap do |result|
sequence.each_slice(n) { |item| result << item }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment