Skip to content

Instantly share code, notes, and snippets.

@havenwood
Created September 24, 2012 23:31
Show Gist options
  • Save havenwood/3779103 to your computer and use it in GitHub Desktop.
Save havenwood/3779103 to your computer and use it in GitHub Desktop.
x = [[1, nil, 50],
[1, 23, nil],
[2, 55, nil],
[4, 5, nil],
[4, nil, 62]]
expected_dates = *1..5
expected_dates.map do |date|
@hash[date] = []
end
@actual_dates = []
x.each { |error| @actual_dates << error.first }
expected_dates.each do |k, v|
@results ||= []
case @actual_dates.count k
when 0
@results << [k, 0, 0]
when 1
@results << [k, 'first match', 0]
when 2
@results << [k, 'first match', 'second match']
end
end
@results
#=> [[5, 0, 0],
[1, "first match", "second match"],
[2, "first match", 0],
[3, 0, 0],
[4, "first match", "second match"],
[5, 0, 0]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment