8
ditht
6y

When the first language you learn is js

Comments
  • 3
    I think it's the verbosity and corruption of functional programming and the fact that this is exported as a module that makes this code so crazy and the fact that he redundantly checks the input 3 times.

    Pretty sure he could just replace this with this:

    if (!Number.isSafeInteger(input)) {
    return false // or throw error...
    } else {
    return (input % 2) === 1
    }
  • 0
    @Noobish Exactly how is this clear? I get the first error, add "if(Number.isNumber(x)) isOdd(x)", and get shit on with another error. And on top of that, console.log(x) gives me "9007199254742448", which is clearly an even number, but this code throws yet another error instead of giving me my answer.

    The only way this code could be considered "clear" would be if it was Java, and each error would be of a different type for the purpose of handling it at different stages within the app. But Java doesn't have dynamic typing anyway, so...
Add Comment