+ 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
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/
+ 3
Miika You are right. They're called bitwise operator but as you said in case of Array they are set operators.
+ 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
+ 1
Got it! Thank you, guys!
0
A | is called a bitwise operators they initialize a and b then calculate the answer