Quote:
Originally Posted by fowlplay4
PHP Code:
function isEven(x) { // missing divide operation return int(x) == (x / 2); } function isEven(x) { return int(x / 2) == (x / 2); }
|
You're missing an operation in the isEven() function!
The way I usually look at it, checking if its even by int(x / 2) == (x / 2) requires four basic operations (int, 2 divides, and a comparison), at least two references (x twice, maybe a third for the int() function call). Modulus requires two basic operations (mod, and a comparison) and only one variable reference.
But yeah I agree, the difference is so small it probably wouldn't matter in most cases.