Sha256: 902a6a9dcbdf24b123407ee9634fc54085eeee82541cca8c0b66e9e735cccfd4

Contents?: true

Size: 617 Bytes

Versions: 1

Compression:

Stored size: 617 Bytes

Contents

require "signal_tools/stock_data"
require "signal_tools/stock"

module SignalTools
  def self.sum(array)
    array.inject(0) {|accum, c| accum + c.to_f }
  end

  def self.average(array)
    return nil if !array || array.size == 0
    sum(array).to_f / array.size
  end

  # Truncates all arrays to the size of the shortest array by cutting off the front
  # of the longer arrays.
  def self.truncate_to_shortest!(*arrays)
    shortest_size = arrays.inject(arrays.first.size) { |size, array| array.size < size ? array.size : size }
    arrays.each { |array| array.slice!(0...(array.size - shortest_size)) }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
signal_tools-0.2.2 lib/signal_tools.rb