0
Ruby Code
Kindly someone explain how this code working in ruby ? a=[1,4,9,16]; b=[1,8,27,64,125]; c=a|b d=a&b print c.length,d.length
2 Answers
+ 1
thanks so much it's so helpful.
0
In line 1 you create an array of numbers.
You did the same in line 2.
in line 3 you did an UNION operation
put the values in a OR b in c. you will have 8 numbers in c.
[1, 4, 9, 16, 8, 27, 64, 125] (no number is repeated)
in line 4 you did an INTERSECTION operation
what values that are in a AND b.
put them in d. There is only [1]
in line 5 you print the length of c (8) and d (1)