Last active
December 24, 2015 08:59
-
-
Save ashmckenzie/6774234 to your computer and use it in GitHub Desktop.
Create the smallest solution to take the given data hash and produce the desired output (using pure Ruby stdlib)
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
# Source data | |
# | |
data = { | |
name: 'John Smith', | |
age: 45, | |
address: '123 Here St', | |
email: '[email protected]' | |
} | |
# Code here.. | |
# Desired output | |
# | |
# {:name=>"John Smith", :email=>"[email protected]"} |
@ashmeckenzie neat!
Because all the neat solutions were taken (I was going with Stu). I give you:
[:name, :email].map {|k| Hash[k, data[k]] }.inject(:update)
@ashmckenzie BAM, #map and #inject !
@gabrielrotbart obfuscation is the best solution
Here's the winning solution*
> data.win
=> {:name=>"John Smith", :email=>"[email protected]"}
*assuming you're using my personally-patched ruby
class Hash
def win
{:name=>"John Smith", :email=>"[email protected]"}
end
end
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@ashmckenzie absolutely shameful :)