The source code to compare two arrays using the eql?() method is given below. The given program is compiled and executed successfully.
# Ruby program to compare two arrays
# using eql?() method
arr1 = [10,20,30,20,50,30];
arr2 = [10,50,30,40,60,70];
arr3 = [10,20,30,20,50,30];
if arr1.eql?(arr2)
print "arr1 and arr2 are equal.\n";
else
print "arr1 and arr2 are not equal.\n";
end
if arr1.eql?(arr3)
print "arr1 and arr3 are equal.\n";
else
print "arr1 and arr3 are not equal.\n";
end
Output:
arr1 and arr2 are not equal.
arr1 and arr3 are equal.
Explanation:
In the above program, we created 3 arrays arr1, arr2, arr3 with some elements. Then we compared arrays using the eql?() method and printed the appropriate message.
Program/Source Code:
The source code to compare two arrays using the eql?() method is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we created 3 arrays arr1, arr2, arr3 with some elements. Then we compared arrays using the eql?() method and printed the appropriate message.
need an explanation for this answer? contact us directly to get an explanation for this answer