Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/macroape/support/partial_sums.rb

Instance Method Summary collapse

Instance Method Details

#partial_sums(initial = 0.0) ⇒ Object

=> 5, 4 => 3, 3 => 2.partial_sums == 3=>7, 4=>10



10
11
12
13
14
15
16
# File 'lib/macroape/support/partial_sums.rb', line 10

def partial_sums(initial = 0.0)
  sums = initial
  sort.each_with_object({}){|(k,v), hsh|
    sums += v
    hsh[k] = sums
  }
end