Josselin
10/21/2006 6:30:00 AM
On 2006-10-20 13:40:44 +0200, Robert Klemme <shortcutter@googlemail.com> said:
> On 20.10.2006 13:35, Josselin wrote:
>> On 2006-10-20 10:32:18 +0200, Robert Klemme <shortcutter@googlemail.com> said:
>>
>>> On 20.10.2006 09:59, Josselin wrote:
>>>> ldom = 30 # variable (last day of a month...)
>>>>
>>>> # array init to 0
>>>> @obk = []
>>>> 1.step(ldom, 1) do |i|
>>>> @obk[i] = 0
>>>> end
>>>
>>> @obk = Array.new(ldom, 0)
>> better , avoiding @obk[0] = nil ...
>>>
>>>> I am filling an array as follows (part of a larger filling scheme) :
>>>> ----
>>>> #fiiling the array upon another array content
>>>> # but I'd like to AVOID filling the first and last position in this loop....
>>>> obdays.each do |bd|
>>>> @obk[bd] = 1
>>>> end
>>>> ------
>>>> # ajusting first and last position (in the larger scheme)
>>>> @obk[obdays.first] += -1
>>>> @obk[obdays.last] += -2
>>>
>>> I am not exactly sure what problem you have with this approach. Here
>>> is a different one
>>>
>>> obdays.each_with_index do |bd, idx|
>>> case idx
>>> when 0
>>> # ignore, @obk[bd] is 0 already
>>> when obdays.length - 1
>>> # set to 1 + (-2) = -1
>>> @obk[bd] = -1
>>> else
>>> @obk[bd] = 1
>>> end
>>> end
>>>
>>> Does that help?
>>>
>>> robert
>>
>> yes and no, I cannot test @obk[bd] == 0 as it may change.... as
>> indicated in one of my response post
>
> ??? There is no test for @obk[bd] == 0 in the code above. It's a bit
> difficult to guess what you really want with the information I have
> seen.
>
> Cheers
>
> robert
Thanks Robert, I solved the problem creating a sub-range without the
first and last position of the the initial range
other_booking_days = (bk.start_at.day..bk.end_at.day)
@obk[other_booking_days.first] += -1
obd = (bk.start_at.day+1..bk.end_at.day-1)
obd.each {|bd| @obk[bd] = 1 }
@obk[other_booking_days.last] += -2
all range is initialized to 0
first and last position in the range act like incremental counters..
in between just get a value