Array Subtraction and Difference : Array Subtraction « Array « Ruby






Array Subtraction and Difference


# You can compare two arrays by subtracting one against the other. 
# This technique removes any elements from the main array that are in both arrays:
x = [1, 2, 3, 4, 5]
y = [1, 2, 3]
z = x - y
puts z.inspect

 








Related examples in the same category