Skip to content

Instantly share code, notes, and snippets.

@justincampbell
Created July 30, 2013 15:13
Show Gist options
  • Save justincampbell/6113851 to your computer and use it in GitHub Desktop.
Save justincampbell/6113851 to your computer and use it in GitHub Desktop.
values = ["a", "b", "c"]
result = (1..values.length).inject([]) { |buffer, count|
buffer |= values.combination(count).to_a
}.map(&:join)
result # => ["a", "b", "c", "ab", "ac", "bc", "abc"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment