is-even
is-even copied to clipboard
saving unnecessary work, you don't need to check the numbers one by one
An even number is one that is divisible by 2, to know it, it is enough to know if the module of the division is equal to 0. To know this result, in javascript the function % (Module) is used, example:
2 % 2 = 0; 5 % 2 = 1; ...
so it is only necessary to return if the result of the comparison of whether the module is equal to 0 or not
fake
not going to work
This is not going to work! The function % (Module) does no exist!
Please Inform you next time before sending!
Sincerly
Why is this not going to work? (I don't know much javascript).
This is not going to work! The function % (Module) does no exist!
Please Inform you next time before sending!
Sincerly
tell that to MDN Web doc: https://developer.mozilla.org/es/docs/Web/JavaScript/Reference/Operators/Remainder
and ecma262 specification: https://tc39.es/ecma262/#sec-multiplicative-operators
honestly, I am not going to insist on a thread that seems more troll than something useful, I suggest that before saying that it does not work, try it
you're taking it too seriously bro
current approach is best practice, this fancy 'modulus' operator is too untested for prod environments
tell that to MDN Web doc:
it doesnt say "Module" anywhere on that site all it says is "Resto"
That's obviously not going to work...
You should probably change profession because you clearly dont know what you're doing
The % is the percentage operator... You only have to do 75%4 That will return 3, which is the 75% of 4... There is too much to learn in the ways of coding for you yet...
An even number will lack the "ones" bit in its data and thus can be easily checked via bitwise operations. Due to how bitwise wont work on floats and how JS doesnt have any int variables it has to do the extra process of converting the float to int then back to float. Tho that process is still faster then using the modulo operation (and completely unneeded on other languages most of the time as well as they have ints).
function IsEven(num) {
return !(num & 1);
}
An even number will lack the "ones" bit in its data and thus can be easily checked via bitwise operations.
bits arent wise tho