Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

is-odd doesn't have any tests for handling zero. What would they be anyway?

What is-odd does is to throw an exception if you pass anything that isn't a safe integer or a string representation of a safe integer. Otherwise it just returns n % 2 === 1 (after converting string to int if necessary)



You don't want to start a religious war between the people who believe zero is special, and the ones who believe it should throw an error if you pass a string, and the people who believe it should attempt to convert the string to an integer, and the people who believe you should either round or truncate when the parameter is a floating point number, and the people who disagree about which direction to round, and the people who can't agree whether you should truncate towards zero or negative infinity.


> should either round or truncate when the parameter is a floating point number

Isn't the parameter always floating point in Javascript? (which does mean a package like isOdd will have to incorporate some level of mysticism...)


Let the fight begin! It goes well with some popcorn.

I can understand how fundamental education teachers don't grasp modern Algebrism and believe that Math is formed by fundamental, sacred definitions. But programmers ought to know better.


And my favorite case - that zero is false. (!!0)


Yeah but point being, if you need to use is-odd, what you probably need more is something tailored to your particular application.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: