Hi All.
In the exercise I'm trying to solve I have 2 arrays of names and what I
have to do in a subtraction, a union and an intersection of arrays, the
issue is that I have to use basic functions as a for loop such as this
is as indicated by the exercise, and while I understand the logic of
what to do, I can not think how to implement it correctly.
Exercise such functions done with Ruby or unused cycles would look like:
···
#######################################################################
op_sys = ["Fedora", "SuSE", "Tuquito", "Windows", "MacOS"]
linux_sys = ["Tuquito", "SuSE", "PCLinuxOS", "Ubuntu", "Fedora"]
sub = (op_sys) - (linux_sys)
int = (op_sys) & (linux_sys)
uni = (op_sys) | (linux_sys)
puts "Subtraction: # {rest}"
puts "intersection: # {int}"
puts "Union: # {uni}"
#########################################################################
Now if I try to do with basic functions, such as subtraction of arrays:
################################################################
op_sys = ["Fedora", "SuSE", "Tuquito", "Windows", "MacOS"]
linux_sys = ["Tuquito", "SuSE", "PCLinuxOS", "Ubuntu", "Fedora"]
for i in 0 .. 4
op_sys if [i]! = linux_sys [i]
subtraction = [i] = op_sys [i]
end
end
puts "Subtraction: # {subtraction}"
#################################################################
Here is a little tricky, and not calculated well, I've been trying many
combinations, but do not know how to calculate the difference of arrays
using basic functions properly.
I accept any suggestions. Thank you.
--
Posted via http://www.ruby-forum.com/.