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 +4 -4
- data/ARRAY_README.md +8 -0
- data/README.md +1 -1
- data/lib/darthjee/core_ext/array.rb +11 -0
- data/lib/darthjee/core_ext/version.rb +1 -1
- data/spec/integration/yard/array_spec.rb +8 -0
- data/spec/lib/array_spec.rb +8 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76f54a19a0bf4ae4892e60d0473ac649c2c63966
|
4
|
+
data.tar.gz: '0183bd9098a782cfc4792c480435ec3ec93cec0e'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e24c2851a5462ec6e865e1779a68c4e625c2ea23b95298171261ff33b63ac9d0104ce584e32628c0825d355a4a49bf0b6a4b21b00a5ceaa6bd21dda67483ea4
|
7
|
+
data.tar.gz: 406126966cfd866c2576eeb1fb112ada5daae171e3ebbc87208b7d3d6fc9a0706c0e78899b52882525e26e6bcb98f4b27aaccefe4e6e7602ffddd66c057bfee1
|
data/ARRAY_README.md
CHANGED
data/README.md
CHANGED
@@ -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
|
#
|
@@ -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
|
|
data/spec/lib/array_spec.rb
CHANGED
@@ -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
|
|