Basic Operations For Arrays In Ruby

Posted by Weston Ganger

After developing for a long time I wanted a way to get the uniq values from two arrays combined. Turns out there is a very simple union operation for this exact problem.

Here I will show four basic operations for Arrays:


x = [1,2,3]
y = [2,3,4,5]

#intersection
x & y # => [2,3]

# union
x | y # => [1,2,3,4,5]

# difference
x - y # => [1]

# combination
x + y # => [1,2,3,2,3,4,5]


Related External Links:

Article Topic:Software Development - Rails

Date:November 29, 2016

Recommended Posts