When you get really bored, and want to find a problem for this solution:

Getting the intersection and lowest values of a hash. :)

def hash_intersect_min(*hashes)
  hashes.inject(hashes.pop.dup) { |i,h| i.delete_if { |k,v| hv=h[k]; next true unless hv; i[k]=hv if hv<v; false }; i }
end

So the following:

hash_intersect_min({:a => 1, :d => 2, :k => 2, :j => 6}, {:k =>1, :a => 4, :j => 4}, {:e => 4, :k => 2, :d => 4, :j => 9})

Produces:

{:k=>1, :j=>4}

I’m completely aware of the extreme triviality this introduces to most programming, but ya know what… sometimes you need quirky crap to get you through the day. :) Happy coding!

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>