Tsunokiette
Member
I posted a method to return if a number is odd or not a while ago somewhere, and it got butch... *cough* enhanced :D and I learned a few things.
Now I once again post an almost useless method, except now it works with any number of arguements and will return the result in an array unless there is only one number .... or none. It will also allow any number of arrays and any combination of arrays and singular numbers.
If you use an array as an arguement, then the result will be in -
local_variable[index_of_array,index_of_result]
Here's the method -
To use make sure you allays use a variable of some sort.
IE:
number_odd = odd?(some_array,3,2,89,another_array)
EDIT : Realized a small error, fixed now.
Now I once again post an almost useless method, except now it works with any number of arguements and will return the result in an array unless there is only one number .... or none. It will also allow any number of arrays and any combination of arrays and singular numbers.
If you use an array as an arguement, then the result will be in -
local_variable[index_of_array,index_of_result]
Here's the method -
Code:
def odd?(*numbers)
if *numbers.size == 1 and !*numbers[0].is_a?(Array)
result = (*numbers[0] % 2 = 1)
elsif *numbers.size == 1 and *numbers[0].is_a?(Array)
for i in 0...*numbers[0].size
result[i] = (*numbers[0,i] % 2 = 1)
end
elsif *numbers.size == 0
return p "No numbers provided for 'odd?' method."
else
for i in 0...(*numbers.size)
if *numbers[i].is_a(Array)
for j in 0...(*numbers[i].size)
result[i,j] = (*numbers[i,j] % 2 = 1)
end
else
result[i] = (*numbers[i] % 2 = 1)
end
end
end
return result
end
To use make sure you allays use a variable of some sort.
IE:
number_odd = odd?(some_array,3,2,89,another_array)
EDIT : Realized a small error, fixed now.