Class: Array

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

Overview

##

This extension adds utility methods to the Array class.

##

Constant Summary

Constants included from ImmosquareExtensions

ImmosquareExtensions::VERSION

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: 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

##


21
22
23
# File 'lib/immosquare-extensions/array.rb', line 21

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"

]

##


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

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