Ruby program to find the common elements from two arrays

Hi everyone do you know about Ruby program to find the common elements from two arrays. With this article, you can clearly see everything you have in doubt.

Ruby program to find the common elements from two arrays

Ruby program to find the common elements from two arrays

# Ruby program to find the common 
# elements from two arrays

arr1 = ["RAM","KRISHNA","SHIV","GANESH"];
arr2 = ["KRISHNA","RAM"];

arr3 = arr1 & arr2;

print "Common array elements:\n#{arr3}";
Common array elements:
["RAM", "KRISHNA"]

Final Words

Through this article, we have come to know clearly that Ruby program to find the common elements from two arrays. If you have any doubts please leave a comment via the comment box.

Hi, I'm Selva a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Deekshi. Here, I post about programming to help developers.

Share on:

Leave a Comment