mean_median_mode 0.2.3 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cc14dc3d91e5ba18d12ae0ff150c040a5adf2b8f
4
- data.tar.gz: 4c31c9dbe418bc67f8f7519509fd1eedc73dd0f8
3
+ metadata.gz: 00ce111a98043f335868abb4dd807fee4f5b88a8
4
+ data.tar.gz: 747200b676b7364b2c39dd18f8d03f668cbe302b
5
5
  SHA512:
6
- metadata.gz: 01c6cdcd91d04b054110452c3126c3c1a234400487097894e14a0b052aec47ed8cf5316c93381613eac42a562046e5ced71b8fc923e4fd644bc7b38bb2906f04
7
- data.tar.gz: 3a3781bfe7e554e84715f729febb70438cc2b9c165eae4c7154d930b5b6e70f945c34a65ec6948d7ef5056121139ce0b323c128e5b16580308189ce0f3685356
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
- return ans = (sum_of_array>0 && total>0) ? (sum_of_array.to_f/total.to_f) : 0
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-1]
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
@@ -8,7 +8,7 @@ module MeanMedianMode
8
8
  total = num_arr.count
9
9
  ans = 0
10
10
  ans = num_arr.detect{ |e| num_arr.count(e) > 1 } if total
11
- return ans
11
+ self << ans
12
12
  end
13
13
  end
14
- end
14
+ end
@@ -1,3 +1,3 @@
1
1
  module MeanMedianMode
2
- VERSION = "0.2.3"
2
+ VERSION = "0.3.0"
3
3
  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.2.3
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-15 00:00:00.000000000 Z
11
+ date: 2015-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler