Ruby Code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

17th May 2018, 9:33 AM
Wasim Abbasi
Wasim Abbasi - avatar
2 Answers
+ 1
thanks so much it's so helpful.
21st May 2018, 9:42 AM
Wasim Abbasi
Wasim Abbasi - avatar
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)
17th May 2018, 10:05 AM
Ulisses Cruz
Ulisses Cruz - avatar