Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • Good answer. Might want to clarify that the i < len condition is a boundary condition too. Commented Dec 9, 2013 at 16:11
  • @SomeGuy "hardcoded boundary condition"? Commented Dec 9, 2013 at 16:13
  • I think this is a good answer. Do you feel saying "hardcoded boundary condition" is a meaningful way to distinguish this condition from that which @SomeGuy described? Commented Dec 9, 2013 at 16:15
  • @thomas: I'm not totally comfortable with "magic numbers" like the one in your if. Generally, you would define a constant somewhere, like MAX_VALUE, and use the constant for the condition instead of the magic number. Commented Dec 9, 2013 at 16:15
  • 1
    The 50 is a magic number. Normally, instead of "hardcoding" a stop value there, you would define a constant at the top of your script, such as MAX_VALUE, and say for (var i = 0; i < len && i < MAX_VALUE; i++) But, your mileage may vary; if this is just a small bit of Javascript, it may not matter. My point is that the "hard coding" aspect of this is not particularly significant. Commented Dec 9, 2013 at 16:23