I am translating a code from Python to Julia. I have the following array:
_DAYS_IN_MONTH = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
And the following line of code:
_DAYS_IN_MONTH[index] - _DAYS_IN_MONTH[index - 1]
The idea is that, if index - 1 is evaluated to -1, then we will get the last element of the array, which is exactly what we need in this case. However, this does not work in Julia. Of course, I can write something like this:
if index == 1
_DAYS_IN_MONTH[index] - _DAYS_IN_MONTH[end]
else
_DAYS_IN_MONTH[index] - _DAYS_IN_MONTH[index - 1]
end
But I wonder if there is a more elegant and "Julian" way of doing this.