This file contains 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
{ | |
" ": " ", | |
"!": "!", | |
"\"": """, | |
"#": "#", | |
"$": "$", | |
"%": "%", | |
"&": "&", | |
"'": "'", | |
"(": "(", |
This file contains 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
class Hash | |
def keys_to_sym | |
self.each_with_object({}) do |(k, v), h| | |
h[k.to_sym] = v.class == Hash ? v.keys_to_sym : v | |
end | |
end | |
end | |
hash = {"a" => 1, "b" => 2, "c" => {"A" => "foo", "B" => "bar"}} | |
hash.keys_to_sym |
This file contains 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
hash = { a: 1, b: 2, c: 3 }; | |
total = $.map(hash, function(v, k){return v;}).reduce(function(x, y){return x + y;}); | |
// => 6 |
This file contains 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
Encounter E437: terminal capability "cm" required | |
Press ENTER or type command to continue |
This file contains 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
ary = [ { a: 1, b: 2, c: 3 }, { b: 3, c: 2 }, { a: 2, c: 4 } ] | |
key = :a | |
max = ary.select{ |h| h[key] }.map{ |h| h[key] }.max # => 2 | |
min = ary.select{ |h| h[key] }.map{ |h| h[key] }.min # => 1 |