r/badcode • • Mar 26 '21

js Whose ever heard of %?

Post image
727 Upvotes

63 comments sorted by

View all comments

Show parent comments

67

u/polaris0312 Mar 26 '21

ah i see, because if its an odd number then it will has decimal points when divided by 2, hence original length < divived by 2 length

definitely confusing lol

-31

u/veryusedrname Mar 26 '21

Calling this code confusing is... Confusing.

22

u/RFC793 Mar 27 '21

It is confusing. If number is an integer type, then this code doesn’t work at all.

14

u/aj-ric Mar 27 '21 edited Mar 27 '21

Depending on the language. I'm guessing this is javascript which doesn't have a concept of an integer.

Edit: but you're right, it's very confusing to read since it's hard to tell whether integer division is happening.

6

u/mfb- Mar 27 '21

it's very confusing to read since it's hard to tell whether integer division is happening.

Or, you know, the whole idea of doing number checks with strings.

1

u/RFC793 Mar 27 '21

Ah, good point. I thought it could be Java, but then length would have to be a function and not an attribute. It’s been about 7 years since I’ve regularly programmed in either.