class Object
Public Instance Methods
make_array(arg)
click to toggle source
Return an argument as an array for use with arithmetic methods
# File lib/array_arithmetic.rb, line 183 def make_array(arg) return [arg] end
update_array_length(arr_one, arr_two)
click to toggle source
Takes in two arrays of unequal length passed to the arithmetic method Recycles values from the shorter array Returns an array containing two arrays of equal length
# File lib/array_arithmetic.rb, line 190 def update_array_length(arr_one, arr_two) if arr_one.length < arr_two.length adjusted_arr_one = [] arr_two.each_with_index do |value, index| if arr_one.length == 1 adjusted_arr_one << arr_one[0] elsif index >= arr_one.length if index >= arr_one.length * 2 adjusted_arr_one << arr_one[index % arr_one.length] else adjusted_arr_one << arr_one[index - arr_one.length] end else adjusted_arr_one << arr_one[index] end end return adjusted_arr_one, arr_two elsif arr_one.length > arr_two.length adjusted_arr_two = [] arr_one.each_with_index do |value, index| if arr_two.length == 1 adjusted_arr_two << arr_two[0] elsif index >= arr_two.length if index >= arr_two.length * 2 adjusted_arr_two << arr_two[index % arr_two.length] else adjusted_arr_two << arr_two[index - arr_two.length] end else adjusted_arr_two << arr_two[index] end end return arr_one, adjusted_arr_two end end