From: ggmichaelgo@...
Date: 2021-08-02T01:26:13+00:00
Subject: [ruby-core:104744] [Ruby master Feature#18057] Introduce	Array#average

Issue #18057 has been updated by ggmichaelgo (Michael Go).


Hello Sawa! I apologize for the confusion... (this is my first time contributing, and I am hoping to contribute more :D)

For this function, I am trying to calculate the arithmetic mean.
I have been developing a stock price analytics algorithm, and I would be using this function to calculate the moving average price.

[ref on Moving Average](https://www.investopedia.com/terms/m/movingaverage.asp)

The block is used like the rb_ary_sum, and it is use to calculate the sum of the array.






----------------------------------------
Feature #18057: Introduce Array#average
https://bugs.ruby-lang.org/issues/18057#change-93079

* Author: ggmichaelgo (Michael Go)
* Status: Open
* Priority: Normal
----------------------------------------
Introduce Array#average to calculate the average value of an array.

```ruby
array = [1, 2, 3]
array.average # 3

array = [1.5, 2.2, 3.1]
array.average(&:round) # 3.5

array = [-3, -2, -1]
array.average { |e| e.abs } # 3
```



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>