Created
May 7, 2011 05:25
-
-
Save basicxman/960223 to your computer and use it in GitHub Desktop.
Ian wanted something to dynamically get sets of keys.
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
| require 'pp' | |
| $glob_store = [] | |
| def get_key_sets(temp, previous_set = nil) | |
| temp.each_with_index do |value, index| | |
| if previous_set.nil? | |
| new_set = [] | |
| else | |
| new_set = previous_set.dup | |
| end | |
| new_set << index | |
| $glob_store << new_set | |
| if value.is_a? Array | |
| get_key_sets(value, new_set) | |
| end | |
| end | |
| end | |
| temp = [ | |
| [ | |
| [ | |
| 9, | |
| 8, | |
| [ | |
| 9 | |
| ] | |
| ] | |
| ], | |
| [ | |
| 0, | |
| 2, | |
| 4 | |
| ] | |
| ] | |
| get_key_sets(temp) | |
| puts; puts; puts; | |
| $glob_store.each do |key_set| | |
| puts key_set.join("->") | |
| end | |
| puts; puts; puts; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment