Class: Array
- Inherits:
-
Object
- Object
- Array
- Includes:
- ImmosquareExtensions::SharedMethods
- Defined in:
- lib/immosquare-extensions/array.rb
Overview
##
This extension adds utility methods to the Array class.
##
Instance Method Summary collapse
-
#mean ⇒ Object
## Calculate the average (mean) of an array of numbers.
-
#to_beautiful_json(**options) ⇒ Object
## A json file can be a hash or an array.
Instance Method Details
#mean ⇒ Object
##
Calculate the average (mean) of an array of numbers. The mean is the sum of the numbers divided by the count.
Reference: www.chrisjmendez.com/2018/10/14/mean-median-mode-standard-deviation/
Examples: [1, 2, 3, 4, 5].mean => 3.0 [2, 4, 6].mean => 4.0
##
19 20 21 |
# File 'lib/immosquare-extensions/array.rb', line 19 def mean sum(0.0) / size end |
#to_beautiful_json(**options) ⇒ Object
##
A json file can be a hash or an array. This method will test.json [
{"name": "Alice"},
{"name": "Bob"},
123,
"string"
]
##
33 34 35 36 37 38 39 |
# File 'lib/immosquare-extensions/array.rb', line 33 def to_beautiful_json(**) = {}.merge() [:align] = true if ![true, false].include?([:align]) [:indent_size] = 2 if [:indent_size].to_i == 0 || [:indent_size].to_i > 10 dump_beautify_json(self, [:align], [:indent_size]) end |