is-even icon indicating copy to clipboard operation
is-even copied to clipboard

saving unnecessary work, you don't need to check the numbers one by one

Open KyoX opened this issue 3 years ago • 13 comments

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

KyoX avatar Aug 17 '21 15:08 KyoX

fake

wiger3 avatar Aug 17 '21 15:08 wiger3

not going to work

niltonfrederico avatar Aug 17 '21 15:08 niltonfrederico

This is not going to work! The function % (Module) does no exist!

Please Inform you next time before sending!

Sincerly

Yariya avatar Aug 17 '21 15:08 Yariya

Why is this not going to work? (I don't know much javascript).

ju-sh avatar Aug 17 '21 16:08 ju-sh

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

KyoX avatar Aug 17 '21 16:08 KyoX

you're taking it too seriously bro

RishabSwift avatar Aug 17 '21 16:08 RishabSwift

current approach is best practice, this fancy 'modulus' operator is too untested for prod environments

chrissmiller avatar Aug 17 '21 16:08 chrissmiller

tell that to MDN Web doc:

it doesnt say "Module" anywhere on that site all it says is "Resto"

wiger3 avatar Aug 17 '21 17:08 wiger3

That's obviously not going to work...

carlosguerra97 avatar Aug 17 '21 20:08 carlosguerra97

You should probably change profession because you clearly dont know what you're doing

kirkegaard avatar Aug 17 '21 22:08 kirkegaard

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...

carlosguerra97 avatar Aug 17 '21 23:08 carlosguerra97

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);
}

northmatt avatar Aug 22 '21 09:08 northmatt

An even number will lack the "ones" bit in its data and thus can be easily checked via bitwise operations.

bits arent wise tho

wiger3 avatar Aug 22 '21 12:08 wiger3