Array's methods and operators in Ruby

What’s the method/operator between the two arrays for purpose like,
arr1=[1,2,3,4,5,6,7,8,9,10]
arr2=[2,5,9]
#code to remove the item of arr2 from arr1.
p arr1

#=>[1,3,4,6,7,8,10]

another is,
arr3=[a,b,c,d,e,f,g,h,i,j,k,l,m,n,o]
arr4=[a,i,n]
#code to remove the item of arr4 from arr3.
p arr3

#=>[b,c,d,e,f,g,h,j,k,l,m,o]

Selvag R. wrote in post #1134352:

What’s the method/operator between the two arrays for purpose like,
arr1=[1,2,3,4,5,6,7,8,9,10]
arr2=[2,5,9]
#code to remove the item of arr2 from arr1.
p arr1

#=>[1,3,4,6,7,8,10]

another is,
arr3=[a,b,c,d,e,f,g,h,i,j,k,l,m,n,o]
arr4=[a,i,n]
#code to remove the item of arr4 from arr3.
p arr3

#=>[b,c,d,e,f,g,h,j,k,l,m,o]

p arr1 - arr2

say method to do that.

The method is subtracting one array from another. I know it seems too
simple, but that’s what Ruby’s like. Lots of amazingly simple methods
which would be complex in another language :slight_smile:

arr1 - arr2

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs