95

# You wish you had these skills (oc)

• 3
i % 2 == 0
• 1
@qookie lol that's the second one
• 6
isEven(in){
If(in ==2) return true;
return isEven(in-2);
}

Welcome to functional programming
• 15
@RazorSh4rk that would be infinitely recursive given an odd input :/
• 1
• 1
I don't understand the first 1.
• 1
@jaaywags I think it's doing a bitwise and on x and 1 and inverting it, so zeroes out all bits but the last which is flipped. Ie 6 is ~(110 & 001) = ~0 = 1 = true. 7 is ~(111 & 001) = ~1 = 0 = false .

I THINK.
• 1
@RazorSh4rk what happens if the original parameter is a negative number?
• 0
@tizo would eventually overflow to +ve again...but infinite recursion for odd numbers...
• 3
The recursion in the last one cracked me up honestly XD
• 0
@dontPanic what recursion? IsEven4 could be anything!
• 1
bitwise or gtfo
• 2
Even after all those efforts it is wrong since 36 is an even number😓
• 0
Or with a bit attention to the architecture you're working on:

even = (n << 7) >> 7;

And it will contain 0 or 1, basically you shift left by 7 all the nunber bits, so when you shift back by 7 you can see that all the bits except the lsb will be zero. The possibile results will be 1 or 0.
• 0
@Shai oh XD i thought it was the isEven function
• 0
@Shai haha I renamed it and forgot to change the caller
• 0
\$isEven = (int(\$x / 2) == (\$x / 2));
• 0
var isEven = function(x) {
while (x > 2) x -= 2;
return x == 2;
}
• 3
npm install is-even

const isEven = require('is-even');

... which actually depends on is-odd...
• 0
@Verstrahlter 0/10 js library name not hip enough
• 1
@featurenotbug well, it's the actual module for this.. https://npmjs.com/package/is-even/
• 1
@Verstrahlter LMAO that's fuckin gold.

>> require('is-odd'); return !isOdd(I);
• 1
tbh: I would've never thought of !(x & 1); ^^'
• 1
@Krokoklemme i suggest you take a look at bitwise tricks there's plenty of things you can do with those makes your life easier. there's a post full of those in stack overflow
• 0
@Verstrahlter @featurenotbug

Worst part is that is-odd has a dependency on is-number, which depends on kind-of.