Rip readability tho... but yeah the second option is preferable using .includes() and the one which OP mentioned, I was just messing around with the ~ operator
A boolean is unnecessary since values have truthiness and falsiness - -1 will become a falsy value (0), everything else will be truthy (negative numbers). Converting manually to a Boolean is inefficient and unnecessary
You can shorten this to:
Or, using something much more readable:
The first time I saw the
~(Bitwise NOT) operator being usedI tried it and it gives a negative number if the element is present and
0if it is not.So why not use
!!in front of it which will give the answer in a booleanRip readability tho... but yeah the second option is preferable using
.includes()and the one which OP mentioned, I was just messing around with the~operatorA boolean is unnecessary since values have truthiness and falsiness -
-1will become a falsy value (0), everything else will be truthy (negative numbers). Converting manually to a Boolean is inefficient and unnecessaryOh yeah that's true, didn't think of that way.
Thank you!