Class: Array

Inherits:
Object
  • Object
show all
Includes:
ImmosquareExtensions::SharedMethods
Defined in:
lib/immosquare-extensions/array.rb

Overview

============================================================## This extension adds utility methods to the Array class. ============================================================##

Instance Method Summary collapse

Instance Method Details

#meanObject

============================================================## Calculate the average (mean) of an array of numbers. The mean is the sum of the numbers divided by the count.

Reference: https://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 [ "Alice", "Bob", 123, "string" ] ============================================================##



33
34
35
36
37
38
39
# File 'lib/immosquare-extensions/array.rb', line 33

def to_beautiful_json(**options)
  options               = {}.merge(options)
  options[:align]       = true if ![true, false].include?(options[:align])
  options[:indent_size] = 2    if options[:indent_size].to_i <= 0 || options[:indent_size].to_i > 10

  dump_beautify_json(self, options[:align], options[:indent_size])
end