Sha256: 3756e3dfc70ae5d3c3a9996416c4f6077886c84d76b13aa809304511cc70f315

Contents?: true

Size: 314 Bytes

Versions: 5

Compression:

Stored size: 314 Bytes

Contents

require_relative 'collect_hash'

class Array
  def partial_sums(initial = 0.0)
    sums = initial
    map{|el| sums += el}
  end
end

class Hash
# {1 => 5, 4 => 3, 3 => 2}.partial_sums == {1=>5, 3=>7, 4=>10}
  def partial_sums(initial = 0.0)
    sums = initial
    sort.collect_hash{|k,v| [k, sums += v]}
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
bioinform-0.1.17 lib/bioinform/support/partial_sums.rb
bioinform-0.1.16 lib/bioinform/support/partial_sums.rb
bioinform-0.1.15 lib/bioinform/support/partial_sums.rb
bioinform-0.1.14 lib/bioinform/support/partial_sums.rb
bioinform-0.1.13 lib/bioinform/support/partial_sums.rb