25

Arrays start from 0... 1?

Comments
  • 12
    Interesting, if the input was 1-12 then it may be more efficient to do this in terms of CPU cycles, one less subtraction per array access. Unconventional but I quite like it!
  • 1
    It's a convention that days/months arrays start from 1. It is also used in Python's calendar built-in module.
  • 3
    Unconventional - it makes me uneasy seeing an array setup that way.
  • 1
    @kunashe It's very convenient to use, not look at. How awkward it would be to do arr[11] and get December?
  • 0
    @DeepSpace you have a point. I suppose it’s necessary to weigh up whether it’s appropriate for the month array to also return an empty string as a valid month.

    I’d be concerned that I may have to make other fudges for cases like:

    $year[$month[0]]
  • 0
    Probably so he can do strings[month]
Add Comment