samuelmarina / is-even

Is a number even?
1.85k stars 193 forks source link

code not Professional in file index.js #155

Open ClickCyber opened 3 years ago

ClickCyber commented 3 years ago

The code supports up to 300K in addition to being long and unnecessary it can be shortened to 6 lines !! example :

isEven = (n)=>{
    if (n % 2 == 1)
        return false;
    return true;
}
samuelmarina commented 3 years ago

What is %? I don't get it

Hocuri commented 3 years ago

Yes, please don't put file size over readability. The old code is perfectly readable, while this would introduce some weird percentage arithmetic. It's safer to write out the cases explicitly.

What I do like in your code is that return true and return false is programmed out explicitly instead of doing some hard-to-read magic like return n % 2 == 0. Maybe you could make a PR that changes:

function isEven(number) {
...

to:

function isEven(number) {
    if (isEvenInternal(number))
        return true;
    return false;
}

function isEvenInternal(number) {
...
Assassin-1234 commented 3 years ago

the thing with modulus operator (%) is that its an untested operator and not fit for production environment, this code is very very professional and useful. We have over a million lines. Yes, that's the symbol of professionalism