ADVERTISEMENT
ADVERTISEMENT

# Ruby program to find the distinct elements from two arrays

Ruby Example: Write a program to find the distinct elements from two arrays.
Submitted by Nidhi, on January 13, 2022

Problem Solution:

In this program, we will find the distinct elements of two arrays using the "|" operator and print the result.

Program/Source Code:

The source code to find the distinct elements from two arrays is given below. The given program is compiled and executed successfully.

```# Ruby program to find the distinct elements
# from two arrays

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

arr3 = arr1 | arr2;

print "Distinct array elements:\n#{arr3}";
```

Output:

```Distinct array elements:
["RAM", "KRISHNA", "SHIV", "GANESH", "MOHAN"]
```

Explanation:

In the above program, we created 2 arrays arr1, arr2. Then we found the distinct elements from arrays using the "|" operator and printed the result.

ADVERTISEMENT
ADVERTISEMENT

Preparation

What's New

ADVERTISEMENT

Top Interview Coding Problems/Challenges!

ADVERTISEMENT

ADVERTISEMENT

Comments and Discussions!

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.