mean_median_mode 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mean_median_mode/mean.rb +2 -2
- data/lib/mean_median_mode/median.rb +11 -2
- data/lib/mean_median_mode/mode.rb +2 -2
- data/lib/mean_median_mode/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00ce111a98043f335868abb4dd807fee4f5b88a8
|
4
|
+
data.tar.gz: 747200b676b7364b2c39dd18f8d03f668cbe302b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7f57b2d2538894c55e3daef150e1ef940a4a03adc9b6841c97348979582fbc05255177fe192ae321dc3dd82061d7ce8c07d4675e65f0d8697b1bc9df02dbc0b
|
7
|
+
data.tar.gz: 3b59700090536f384abcbfb65696c72ed23e7ed2e42c67cbdb0de045ca2d22c039bf2b87564ff256ab2f662fd700c55b17625ea7b844e308e2ebb9695373ba18
|
@@ -7,7 +7,7 @@ module MeanMedianMode
|
|
7
7
|
num_arr = number_array
|
8
8
|
total = num_arr.count
|
9
9
|
if total
|
10
|
-
answer_mean(total, num_arr)
|
10
|
+
self << answer_mean(total, num_arr)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
@@ -15,7 +15,7 @@ module MeanMedianMode
|
|
15
15
|
def answer_mean(total, num_arr)
|
16
16
|
sorted_array = num_arr.sort
|
17
17
|
sum_of_array = sorted_array.inject{|sum,x| sum+x}
|
18
|
-
|
18
|
+
ans = (sum_of_array>0 && total>0) ? (sum_of_array.to_f/total.to_f) : 0
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
@@ -6,18 +6,27 @@ module MeanMedianMode
|
|
6
6
|
puts '*'*80
|
7
7
|
num_arr = num_array
|
8
8
|
total = num_arr.count
|
9
|
+
if total
|
10
|
+
self << answer_median(total, num_arr)
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
protected
|
16
|
+
def answer_median(total, num_arr)
|
9
17
|
if total
|
10
18
|
if total%2==0
|
11
19
|
pos1 = num_arr[((total/2)-1)]
|
12
20
|
pos2 = num_arr[(total/2)]
|
13
21
|
return (pos1+pos2).to_f/2
|
14
22
|
else
|
23
|
+
puts 'else'
|
15
24
|
pos = ((total+1).to_f)/2
|
16
|
-
return num_arr[pos
|
25
|
+
return num_arr[pos]
|
17
26
|
end
|
18
27
|
else
|
19
28
|
return 0
|
20
29
|
end
|
21
30
|
end
|
22
31
|
end
|
23
|
-
end
|
32
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mean_median_mode
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Helios Solutions
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|