Given these declarations:
a = [*1…10]
b = [2,4,6,8]
You can do this:
c = a.select {|i| b.include?(i) }
c.each {|i| puts i}
Or this:
a.each {|i| puts i if b.include?(i) }
Or this:
(a & b).each {|i| puts i }
Steve
Given these declarations:
a = [*1…10]
b = [2,4,6,8]
You can do this:
c = a.select {|i| b.include?(i) }
c.each {|i| puts i}
Or this:
a.each {|i| puts i if b.include?(i) }
Or this:
(a & b).each {|i| puts i }
Steve
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs