5 ms·
> When I ask a candidate to convert an input string of digits to its output integer (e.g. "001234500" to 1234500) equivalent and they don't seem to discern that
by justhadtoo 4y ago
> When I ask a candidate to convert an input string of digits to its output integer (e.g. "001234500" to 1234500) equivalent and they don't seem to discern that's an important distinction, it raises red flags.
Why do you feel this is important? To clarify, what are you testing here?
- layer8 4y agoIt’s important because "001234500" and "01234500" are two strings that don’t compare equal (and that sort in a specific way), but after conversion to an integer they do compare equal. When you use such a value as an ID, for example, the type you use makes an important difference here. It shows that you understand how equality relates to values and data types, and that changing the type of something can make the same conceptual operation behave differently. This is the kind of fundamental technical understanding and precise thinking you want a developer to be absolutely familiar with.
- mattmanser 4y agoActually, in the old days a string number with a leading 0 in javascript got parsed as an octal. You used to have to do parseInt('0012345', 10) to get it to parse properly. That's what I assume the GP is referring to. They changed it in ECMAScript 5. More details here: https://eslint.org/docs/latest/rules/radix https://eslint.org/docs/latest/rules/radix
- sdf4j 4y agoFaced a similar issue in Java. Someone decided it was a good idea to convert string postal codes to int. For sorting... Using Integer.decode()... Everything was ok until a "09677" show up.