darthjee-core_ext 1.7.1 → 1.7.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7a7679a554bc9075b9a2e6495e47f2602834f106
4
- data.tar.gz: ae306ba662a111238d997a02c9f178ace1980421
3
+ metadata.gz: 76f54a19a0bf4ae4892e60d0473ac649c2c63966
4
+ data.tar.gz: '0183bd9098a782cfc4792c480435ec3ec93cec0e'
5
5
  SHA512:
6
- metadata.gz: 3a9024a26c829e10daba4866d666a7b9ce0fb5ec92f89b839f5ca06263056326ceb85a400e2f35e416393b2c62123aeaddb42133d764d25fadd829aa525578ec
7
- data.tar.gz: 4f672dce0e7ea9c55ae670480dfc4306d0776bec49fce1c336d5dfdc15a4927d214c1fe8cb1c5e220255acd47604843efc30bbf985b2c80099f7857e779d256c
6
+ metadata.gz: 7e24c2851a5462ec6e865e1779a68c4e625c2ea23b95298171261ff33b63ac9d0104ce584e32628c0825d355a4a49bf0b6a4b21b00a5ceaa6bd21dda67483ea4
7
+ data.tar.gz: 406126966cfd866c2576eeb1fb112ada5daae171e3ebbc87208b7d3d6fc9a0706c0e78899b52882525e26e6bcb98f4b27aaccefe4e6e7602ffddd66c057bfee1
@@ -1,4 +1,12 @@
1
1
  ## Array
2
+ ### #average
3
+ returns the average of the values in the array
4
+
5
+ ```ruby
6
+ array = [1, 2, 3, 4]
7
+ array.average # returns 2.5
8
+ ```
9
+
2
10
  ### #map_to_hash
3
11
  map returning a hash with the original array for keys
4
12
 
data/README.md CHANGED
@@ -9,7 +9,7 @@ Darthjee/CoreExt
9
9
 
10
10
  Yard Documentation
11
11
  -------------------
12
- https://www.rubydoc.info/gems/darthjee-core_ext/2.7.1
12
+ https://www.rubydoc.info/gems/darthjee-core_ext/1.7.2
13
13
 
14
14
  # Usage
15
15
  This project adds some new methods to the core ruby classes
@@ -21,6 +21,17 @@ module Darthjee
21
21
  Array::HashBuilder.new(self, keys).build
22
22
  end
23
23
 
24
+ # Calculate the average of all values in the array
25
+ #
26
+ # @return [::Float] average of all numbers
27
+ #
28
+ # @example Average of array of integer values
29
+ # array = [1, 2, 3, 4]
30
+ # array.average # returns 2.5
31
+ def average
32
+ sum * 1.0 / length
33
+ end
34
+
24
35
  # Maps the array using the given methods on each
25
36
  # element of the array
26
37
  #
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Darthjee
4
4
  module CoreExt
5
- VERSION = '1.7.1'
5
+ VERSION = '1.7.2'
6
6
  end
7
7
  end
@@ -4,6 +4,14 @@ require 'spec_helper'
4
4
 
5
5
  describe Array do
6
6
  describe 'yard' do
7
+ describe '#average' do
8
+ subject(:array) { [1, 2, 3, 4] }
9
+
10
+ it 'returns the average' do
11
+ expect(array.average).to eq(2.5)
12
+ end
13
+ end
14
+
7
15
  describe '#mapk' do
8
16
  let(:array) { [{ a: { b: 1 }, b: 2 }, { a: { b: 3 }, b: 4 }] }
9
17
 
@@ -5,6 +5,14 @@ require 'spec_helper'
5
5
  describe Array do
6
6
  it_behaves_like 'an array with map_to_hash method'
7
7
 
8
+ describe '#average' do
9
+ subject(:array) { [1, 2, 3, 4] }
10
+
11
+ it 'returns the average' do
12
+ expect(array.average).to eq(2.5)
13
+ end
14
+ end
15
+
8
16
  describe '#mapk' do
9
17
  let(:array) { [{ a: { b: 1 }, b: 2 }, { a: { b: 3 }, b: 4 }] }
10
18
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: darthjee-core_ext
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.1
4
+ version: 1.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darthjee