Skip to content

Instantly share code, notes, and snippets.

@jasoncodes
Created June 25, 2015 08:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasoncodes/028135cc81de6a7afaae to your computer and use it in GitHub Desktop.
Save jasoncodes/028135cc81de6a7afaae to your computer and use it in GitHub Desktop.
keys = [
%w[a 1 x],
%w[a 1 y],
%w[a 2 x],
%w[a 3 x],
%w[a 3 y],
%w[b 3 y],
%w[b 4 z],
]
last_key = keys.first.map { nil }
keys.each do |key|
first_output_index = last_key.zip(key).each_with_index.detect do |pair, index|
pair[0] != pair[1]
end[1]
output_key = ([nil] * first_output_index) + key[first_output_index..-1]
last_key = key
puts key.inspect + ' ' + output_key.inspect
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment