Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR RUBY

ruby inject hash

hash = { foo: 1, bar: 2 }

# sum up all values of the hash
			# start with 0
				  #	/
result = hash.inject(0) { |sum, key_value| sum + key_value.last }
#=> 3
 
PREVIOUS NEXT
Tagged: #ruby #inject #hash
ADD COMMENT
Topic
Name
1+2 =