array_arithmetic 1.0.0 → 1.0.1
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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/array_arithmetic/version.rb +1 -1
- data/lib/array_arithmetic.rb +45 -55
- 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: 3bf9d32c8693b5a4fd9d4e938fa75995c06ffa90
|
4
|
+
data.tar.gz: 202205d2753d74dbd1df50a01dee2b5641fb52ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 293ee75d71d16e78050dc753960e44fcd4e8896787b09116ece487bda123dea5799fdb0a6f7aa6da02796a278cd7875dd3e8743bd2d5f23109cf53fc2195e555
|
7
|
+
data.tar.gz: 1c4ced69993d9208ca83396be31239abf4aefb788cea5a279bb3f75a0de9ad57f3b8b73fa8aeb0c295b478e1d59a284a2cd53b28f55f831fb8eb4d82dca5f257
|
data/Gemfile.lock
CHANGED
data/lib/array_arithmetic.rb
CHANGED
@@ -3,52 +3,13 @@ require "array_arithmetic/version"
|
|
3
3
|
module ArrayArithmetic
|
4
4
|
class Error < StandardError; end
|
5
5
|
|
6
|
-
#Return an argument as an array for use with arithmetic methods
|
7
|
-
def make_array(arg)
|
8
|
-
return [arg]
|
9
|
-
end
|
10
|
-
|
11
|
-
#Takes in two arrays of unequal length passed to the arithmetic method
|
12
|
-
#Recycles values from the shorter array
|
13
|
-
#Returns an array containing two arrays of equal length
|
14
|
-
def update_array_length(arr_one, arr_two)
|
15
|
-
if arr_one.length < arr_two.length
|
16
|
-
adjusted_arr_one = []
|
17
|
-
arr_two.each_with_index do |value, index|
|
18
|
-
if arr_one.length == 1
|
19
|
-
adjusted_arr_one << arr_one[0]
|
20
|
-
elsif index >= arr_one.length
|
21
|
-
adjusted_arr_one << arr_one[index - arr_one.length]
|
22
|
-
else
|
23
|
-
adjusted_arr_one << arr_one[index]
|
24
|
-
end
|
25
|
-
end
|
26
|
-
return adjusted_arr_one, arr_two
|
27
|
-
elsif arr_one.length > arr_two.length
|
28
|
-
adjusted_arr_two = []
|
29
|
-
arr_one.each_with_index do |value, index|
|
30
|
-
if arr_two.length == 1
|
31
|
-
adjusted_arr_two << arr_two[0]
|
32
|
-
elsif index >= arr_two.length
|
33
|
-
adjusted_arr_two << arr_two[index - arr_two.length]
|
34
|
-
else
|
35
|
-
adjusted_arr_two << arr_two[index]
|
36
|
-
end
|
37
|
-
end
|
38
|
-
return arr_one, adjusted_arr_two
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
|
43
6
|
#Adds the values of corresponding indices of two arrays
|
44
7
|
def add(arr_one, arr_two)
|
45
8
|
raise ArgumentError, 'First argument is not an array' unless arr_one.is_a? Array
|
46
9
|
|
47
10
|
result = []
|
48
11
|
|
49
|
-
|
50
|
-
arr_two = make_array(arr_two)
|
51
|
-
end
|
12
|
+
arr_two = arr_two.class != Array ? make_array(arr_two) : arr_two
|
52
13
|
|
53
14
|
if arr_one.length != arr_two.length
|
54
15
|
length_matched_arrays = update_array_length(arr_one, arr_two)
|
@@ -72,9 +33,7 @@ module ArrayArithmetic
|
|
72
33
|
|
73
34
|
result = []
|
74
35
|
|
75
|
-
|
76
|
-
arr_two = make_array(arr_two)
|
77
|
-
end
|
36
|
+
arr_two = arr_two.class != Array ? make_array(arr_two) : arr_two
|
78
37
|
|
79
38
|
if arr_one.length != arr_two.length
|
80
39
|
length_matched_arrays = update_array_length(arr_one, arr_two)
|
@@ -98,9 +57,7 @@ module ArrayArithmetic
|
|
98
57
|
|
99
58
|
result = []
|
100
59
|
|
101
|
-
|
102
|
-
arr_two = make_array(arr_two)
|
103
|
-
end
|
60
|
+
arr_two = arr_two.class != Array ? make_array(arr_two) : arr_two
|
104
61
|
|
105
62
|
if arr_one.length != arr_two.length
|
106
63
|
length_matched_arrays = update_array_length(arr_one, arr_two)
|
@@ -125,9 +82,7 @@ module ArrayArithmetic
|
|
125
82
|
|
126
83
|
result = []
|
127
84
|
|
128
|
-
|
129
|
-
arr_two = make_array(arr_two)
|
130
|
-
end
|
85
|
+
arr_two = arr_two.class != Array ? make_array(arr_two) : arr_two
|
131
86
|
|
132
87
|
if arr_one.length != arr_two.length
|
133
88
|
length_matched_arrays = update_array_length(arr_one, arr_two)
|
@@ -159,9 +114,7 @@ module ArrayArithmetic
|
|
159
114
|
|
160
115
|
result = []
|
161
116
|
|
162
|
-
|
163
|
-
arr_two = make_array(arr_two)
|
164
|
-
end
|
117
|
+
arr_two = arr_two.class != Array ? make_array(arr_two) : arr_two
|
165
118
|
|
166
119
|
if arr_one.length != arr_two.length
|
167
120
|
length_matched_arrays = update_array_length(arr_one, arr_two)
|
@@ -193,9 +146,7 @@ module ArrayArithmetic
|
|
193
146
|
|
194
147
|
result = []
|
195
148
|
|
196
|
-
|
197
|
-
arr_two = make_array(arr_two)
|
198
|
-
end
|
149
|
+
arr_two = arr_two.class != Array ? make_array(arr_two) : arr_two
|
199
150
|
|
200
151
|
if arr_one.length != arr_two.length
|
201
152
|
length_matched_arrays = update_array_length(arr_one, arr_two)
|
@@ -224,3 +175,42 @@ module ArrayArithmetic
|
|
224
175
|
return exponent(array, 0.5)
|
225
176
|
end
|
226
177
|
end
|
178
|
+
|
179
|
+
|
180
|
+
private
|
181
|
+
|
182
|
+
#Return an argument as an array for use with arithmetic methods
|
183
|
+
def make_array(arg)
|
184
|
+
return [arg]
|
185
|
+
end
|
186
|
+
|
187
|
+
#Takes in two arrays of unequal length passed to the arithmetic method
|
188
|
+
#Recycles values from the shorter array
|
189
|
+
#Returns an array containing two arrays of equal length
|
190
|
+
def update_array_length(arr_one, arr_two)
|
191
|
+
if arr_one.length < arr_two.length
|
192
|
+
adjusted_arr_one = []
|
193
|
+
arr_two.each_with_index do |value, index|
|
194
|
+
if arr_one.length == 1
|
195
|
+
adjusted_arr_one << arr_one[0]
|
196
|
+
elsif index >= arr_one.length
|
197
|
+
adjusted_arr_one << arr_one[index - arr_one.length]
|
198
|
+
else
|
199
|
+
adjusted_arr_one << arr_one[index]
|
200
|
+
end
|
201
|
+
end
|
202
|
+
return adjusted_arr_one, arr_two
|
203
|
+
elsif arr_one.length > arr_two.length
|
204
|
+
adjusted_arr_two = []
|
205
|
+
arr_one.each_with_index do |value, index|
|
206
|
+
if arr_two.length == 1
|
207
|
+
adjusted_arr_two << arr_two[0]
|
208
|
+
elsif index >= arr_two.length
|
209
|
+
adjusted_arr_two << arr_two[index - arr_two.length]
|
210
|
+
else
|
211
|
+
adjusted_arr_two << arr_two[index]
|
212
|
+
end
|
213
|
+
end
|
214
|
+
return arr_one, adjusted_arr_two
|
215
|
+
end
|
216
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: array_arithmetic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- C.J. Adeszko
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|