Ruby : Multiple way of multiplication
How to do multiplication in ruby using different concepts
Regular "*" operator
3 * 3 # => 9
Inject *
[1, 2, 3].inject(:*) # => 6 [1, 2, 3].reject(&:zero?).inject(:*) # if 0's
Reduce
[1 ,2 ,3].reduce { |sum, x| sum + x } # => 6
Last updated