+ 1

Please help with this challenge :) for Ruby

I don't get what this means, googling didn't help. what's the output? a=[1,10,11,3] b=[5,1,3] c =(a|b)&b print c[1] don't give me answer just say what "|" here means? Thanks

14th Oct 2019, 4:29 PM
LenaK
LenaK - avatar
6 Respostas
+ 5
They are called bitwise operator not logical operators. Edited :- In case of Array they are set operators. '&' - Intersection '|' - union "|" means combination of both a and b with unique elements. "&" Means common elements in both a and b. Check this bitwise operators:- https://www.google.com/amp/s/www.geeksforgeeks.org/ruby-operators/amp/ Check this Set operators :- http://flats.github.io/blog/2016/02/07/sets-and-set-operators-in-ruby/
14th Oct 2019, 5:06 PM
A͢J
A͢J - avatar
+ 3
Miika You are right. They're called bitwise operator but as you said in case of Array they are set operators.
14th Oct 2019, 6:43 PM
A͢J
A͢J - avatar
+ 1
| and & is a logical operators: | - or, & - and ~ c = (a or b) and b ~ if we take the analogy with JavaScript, then most likely c[1] means to output the second element of the array, since the numbering of arrays starts from zero
14th Oct 2019, 5:04 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
Got it! Thank you, guys!
14th Oct 2019, 5:15 PM
LenaK
LenaK - avatar
0
A | is called a bitwise operators they initialize a and b then calculate the answer
3rd Nov 2019, 2:47 PM
Joshua