Stelmakhin, I really like your answer, in particular this part:
I don’t fully grok what is happening, though, and I am questioning if it really fully works. It looks like you are XORing the number with 0, which in JS is a IEEE-754 64-bit floating-point number, and thus consists of a mantissa and an exponent. I found this link describing number representation in JS.
The first bit of the representation is the sign bit, with a 0-bit indicating positive and 1-bit indicating negative. Since JS has both +0 and -0, I am guessing that “0” as a number is positive and thus begins with a 0-bit, which would produce no change under an XOR. I don’t see how the above checks if the integer is positive or negative. I entered -1^0 into a node repl and got -1, which suggests that the above doesn’t check for negative integers. We may have gotten lucky in the exercise, since no negative integers were provided in realNumberArray.
I am still trying to figure out how the rest of it works, such as how this checks against fractions. When I type 1.5^0 into the node repl, I get 1, so I know it is working, but this isn’t making sense to me. This calculator suggests that 0 is represented as all 0-bits in IEEE-754, so I don’t understand how it is testing anything under an XOR.
This is an old thread which has been necrobumped, but I’ve just seen your question
Bitwise operators in JS actually coerce and truncate their arguments to 32 bit signed integers first before combining into 64 bit js numbers which is the trick being used to test if a value is an integer in that snippet
That being said, it’s not particularly great as it fails for ints larger than 32 bit and is relatively pointless considering we have Number.isInteger which is AFAIK more robust
I have understood everything up to this point. But this is so poorly explained, and seems to me like it’s gone straight into the deep end. It hasn’t built up or given me a chance to learn it. I look at the solution and literally have no idea what’s going on
const squaredIntegers = arr.filter((num) => (num % 2 == 0 && num > 0)).map(x => x * x);
Figuring out what needed to happen wasn’t as difficult as trying to figure out how the syntax went to do it. After realizing my error with Math.sqrt, Math.pow didn’t work because I couldn’t seem to squish it in there anywhere correct. Coming here for help confirmed I was, once again, overthinking it. The dot notation can just keep going like that? That’s awesome!