Module: ArrayExtensions

Defined in:
lib/ruby_extensions.rb

Instance Method Summary collapse

Instance Method Details

#**(other) ⇒ Object



24
25
26
# File 'lib/ruby_extensions.rb', line 24

def **(other)
  map{|x| x * other }
end

#>>(other) ⇒ Object

harmonic operator



29
30
31
# File 'lib/ruby_extensions.rb', line 29

def >>(other)
  map{|x| (x * other) % 360.0 }
end

#avgObject



16
17
18
# File 'lib/ruby_extensions.rb', line 16

def avg
  sum / size.to_f
end

#diffObject



6
7
8
# File 'lib/ruby_extensions.rb', line 6

def diff
  diffop{|x, y| y - x }
end

#diffopObject



10
11
12
13
14
# File 'lib/ruby_extensions.rb', line 10

def diffop
  d1 = dup.unshift(0)
  d2 = dup.push(0)
  (0..size).map{|i| yield(d1[i], d2[i]) }[1...-1]
end

#gmeanObject



20
21
22
# File 'lib/ruby_extensions.rb', line 20

def gmean
  reduce(:*).to_f**(1.0 / size)
end